From 00cc3d9879078aef9fb4f3ab0abcad70bb43e8c2 Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Sat, 27 Apr 2024 18:08:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E4=B8=BAallSettled=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=B9=E9=94=99=E4=BD=99=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 1 + routes/api/iqiyi.js | 5 ++- routes/api/mgtv.js | 5 +-- routes/api/tencentvideo.js | 6 ++-- routes/api/youku.js | 5 +-- routes/danmaku.js | 1 - utils/leancloud.js | 72 -------------------------------------- 7 files changed, 13 insertions(+), 82 deletions(-) delete mode 100644 utils/leancloud.js diff --git a/app.js b/app.js index 4b33e9a..1974cf3 100644 --- a/app.js +++ b/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}), diff --git a/routes/api/iqiyi.js b/routes/api/iqiyi.js index cc0e265..eef8e88 100644 --- a/routes/api/iqiyi.js +++ b/routes/api/iqiyi.js @@ -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; diff --git a/routes/api/mgtv.js b/routes/api/mgtv.js index 7d0f5c8..e6cf1e6 100644 --- a/routes/api/mgtv.js +++ b/routes/api/mgtv.js @@ -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; diff --git a/routes/api/tencentvideo.js b/routes/api/tencentvideo.js index ff8b16f..132c024 100644 --- a/routes/api/tencentvideo.js +++ b/routes/api/tencentvideo.js @@ -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) { diff --git a/routes/api/youku.js b/routes/api/youku.js index d07ba75..2ae6fa2 100644 --- a/routes/api/youku.js +++ b/routes/api/youku.js @@ -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); diff --git a/routes/danmaku.js b/routes/danmaku.js index 839afc6..9a5caa7 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -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, diff --git a/utils/leancloud.js b/utils/leancloud.js deleted file mode 100644 index 55b8be3..0000000 --- a/utils/leancloud.js +++ /dev/null @@ -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 \ No newline at end of file