mirror of
https://github.com/lyz05/danmaku.git
synced 2026-04-14 18:40:50 +08:00
fix: 改为allSettled,增加容错余量
This commit is contained in:
1
app.js
1
app.js
@@ -25,6 +25,7 @@ app.use(express.urlencoded({ extended: false, validate: { trustProxy: false } })
|
||||
app.use(cookieParser());
|
||||
// 加载静态资源
|
||||
app.use(express.static(path.join(__dirname, "public"), {maxAge: 86400*1000 }));
|
||||
app.use(express.static(path.join(__dirname,"db")))
|
||||
app.use("/assets", [
|
||||
express.static(__dirname + "/node_modules/jquery/dist/",{maxAge: 86400*1000}),
|
||||
express.static(__dirname + "/node_modules/bootstrap/dist/",{maxAge: 86400*1000}),
|
||||
|
||||
@@ -97,14 +97,13 @@ function Iqiyi() {
|
||||
const data = datas[i];
|
||||
let xml = pako.inflate(data, { to: "string" });
|
||||
this.xml2json(xml, contents,datas.length);
|
||||
data[i] = undefined;
|
||||
xml = undefined;
|
||||
datas[i] = null;
|
||||
xml = null;
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
}
|
||||
memory();
|
||||
}
|
||||
datas = undefined;
|
||||
// contents = make_response(contents);
|
||||
memory();
|
||||
return contents;
|
||||
|
||||
@@ -32,8 +32,9 @@ function Mgtv() {
|
||||
|
||||
this.parse = async (promises) => {
|
||||
let contents = [];
|
||||
const values = await Promise.all(promises);
|
||||
let datas = values.map(value => value.data);
|
||||
const results = await Promise.allSettled(promises);
|
||||
let datas = results.filter(result => result.status === 'fulfilled')
|
||||
.map(result => result.value.data);
|
||||
for (const data of datas) {
|
||||
if (data.data.items === null)
|
||||
continue;
|
||||
|
||||
@@ -9,6 +9,7 @@ function Tencentvideo() {
|
||||
this.example_urls = [
|
||||
"https://v.qq.com/x/cover/53q0eh78q97e4d1/x00174aq5no.html",//api lens 50
|
||||
"https://v.qq.com/x/cover/mzc00200fph94nw/l00448ijvve.html",//api lens 91
|
||||
"https://v.qq.com/x/cover/mzc00200fhhxx8d/h0046u6z1iu.html",//api lens 215 OOM
|
||||
];
|
||||
|
||||
this.resolve = async (url) => {
|
||||
@@ -45,8 +46,9 @@ function Tencentvideo() {
|
||||
|
||||
this.parse = async (promises) => {
|
||||
let contents = [];
|
||||
const values = await Promise.all(promises);
|
||||
let datas = values.map(value => value.data);
|
||||
const results = await Promise.allSettled(promises);
|
||||
let datas = results.filter(result => result.status === 'fulfilled')
|
||||
.map(result => result.value.data);
|
||||
|
||||
for (const data of datas) {
|
||||
for (const item of data.barrage_list) {
|
||||
|
||||
@@ -129,8 +129,9 @@ function Youku() {
|
||||
|
||||
this.parse = async (promises) => {
|
||||
let contents = [];
|
||||
const values = await Promise.all(promises);
|
||||
let datas = values.map(value => value.data);
|
||||
const results = await Promise.allSettled(promises);
|
||||
let datas = results.filter(result => result.status === 'fulfilled')
|
||||
.map(result => result.value.data);
|
||||
|
||||
for (const res of datas) {
|
||||
const result = JSON.parse(res.data.result);
|
||||
|
||||
@@ -88,7 +88,6 @@ async function index(req, res) {
|
||||
const path = req.protocol + "://" + req.headers.host + req.originalUrl;
|
||||
const resolve_info = await db.accesscountquery()
|
||||
const hotlist = await db.hotlistquery()
|
||||
console.log(hotlist)
|
||||
res.render("danmaku", {
|
||||
path,
|
||||
urls,
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
const { query } = require("express");
|
||||
const libqqwry = require("lib-qqwry");
|
||||
const qqwry = libqqwry();
|
||||
let AV;
|
||||
// 引入环境变量
|
||||
require("dotenv").config({ path: "../.env" });
|
||||
const DEBUG = !(process.env.DEBUG === "false");
|
||||
|
||||
if (!DEBUG) {
|
||||
AV = require("leancloud-storage");
|
||||
AV.init({
|
||||
appId: process.env.LEANCLOUD_DANMAKU_APP_ID,
|
||||
appKey: process.env.LEANCLOUD_DANMAKU_APP_KEY,
|
||||
serverURL: "https://dbvunek8.lc-cn-n1-shared.com"
|
||||
});
|
||||
};
|
||||
|
||||
function currentDay() {
|
||||
const date = new Date(), y = date.getFullYear(), m = date.getMonth();
|
||||
const start = new Date(date.setHours(0, 0, 0, 0));
|
||||
const end = new Date(date.setHours(23, 59, 59, 999));
|
||||
return [start, end, y, m+1];
|
||||
}
|
||||
|
||||
async function danmakuQuery(date, ip) {
|
||||
if (!AV) return 0;
|
||||
const className = `DanmakuAccess_${currentDay()[2]}_${currentDay()[3]}`;
|
||||
const query = new AV.Query(className);
|
||||
query.greaterThanOrEqualTo("createdAt", date[0]);
|
||||
query.lessThan("createdAt", date[1]);
|
||||
if (ip) query.equalTo("remoteIP", ip);
|
||||
|
||||
query.exists("url");
|
||||
return await query.count();
|
||||
}
|
||||
|
||||
async function add(className, obj) {
|
||||
className = `${className}_${currentDay()[2]}_${currentDay()[3]}`;
|
||||
console.log(className)
|
||||
if (!AV) return;
|
||||
if (obj.remoteIP)
|
||||
obj.ipCountry = getipCountry(obj.remoteIP);
|
||||
const classInstance = AV.Object.extend(className);
|
||||
const record = new classInstance();
|
||||
for (const key of Object.keys(obj)) {
|
||||
record.set(key, obj[key]);
|
||||
}
|
||||
console.log(record.attributes);
|
||||
const o = await record.save()
|
||||
// 成功保存之后,执行其他逻辑
|
||||
console.log(`${className}添加一条记录。objectId:${o.id}`);
|
||||
}
|
||||
|
||||
function getipCountry(ip) {
|
||||
try {
|
||||
const info = qqwry.searchIP(ip);
|
||||
return info.Country + " " + info.Area;
|
||||
} catch (e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { danmakuQuery, currentDay, add };
|
||||
|
||||
if (!module.parent) {
|
||||
}
|
||||
// curl -X POST \
|
||||
// -H "X-LC-Id: {{appid}}" \
|
||||
// -H "X-LC-Key: {{appkey}}" \
|
||||
// -H "Content-Type: application/json" \
|
||||
// -d '{"content": "每个 Java 程序员必备的 8 个开发工具","pubUser": "官方客服","pubTimestamp": 1435541999}' \
|
||||
// https://{{host}}/1.1/classes/Post
|
||||
Reference in New Issue
Block a user