diff --git a/package.json b/package.json index c2be7e8..d633a96 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "scripts": { - "start": "node --max-old-space-size=200 ./bin/www", - "dev": "nodemon --max-old-space-size=200 ./bin/www", + "start": "node --expose-gc --max-old-space-size=200 ./bin/www", + "dev": "nodemon --expose-gc --max-old-space-size=200 ./bin/www", "test": "nyc -a mocha --recursive", "deploy": "flyctl deploy" }, diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..5ecbaf3 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# robots.txt generated at http://www.w3cschool.cn/ +User-agent: * +Disallow: +Crawl-delay: 120 +Disallow: /cgi-bin/ diff --git a/routes/api/iqiyi.js b/routes/api/iqiyi.js index 4c14608..74ed434 100644 --- a/routes/api/iqiyi.js +++ b/routes/api/iqiyi.js @@ -61,6 +61,7 @@ function Iqiyi() { for (const xml of datas) { const json = await xml2js.parseStringPromise(xml) // console.log(json) + global.gc() for (const entry of json.danmu.data[0].entry) { if (!entry.list[0].bulletInfo) continue @@ -74,6 +75,7 @@ function Iqiyi() { contents.push(content); } } + memory() // $('bulletInfo').each(function () { // }) } diff --git a/routes/danmaku.js b/routes/danmaku.js index f713274..ed9ca02 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -17,7 +17,7 @@ function getClientIp(req) { req.connection.socket.remoteAddress; } -async function build_response(url) { +async function build_response(url,req) { try { await axios.get(url) } catch (e) { @@ -38,6 +38,7 @@ async function build_response(url) { ret = await fc.work(url) } catch (e) { console.log(e) + leancloud.danmakuErrorAdd({ip: getClientIp(req), url: url, error: e}) return {msg: '弹幕解析过程中程序报错退出,请等待管理员修复!或者换条链接试试!'} } return ret @@ -54,7 +55,7 @@ router.get('/', async function (req, res, next) { } else { url = req.query.url; download = (req.query.download === 'on'); - ret = await build_response(url) + ret = await build_response(url,req) memory() //显示内存使用量 if (ret.msg !== 'ok') { res.status(403).send(ret.msg) @@ -69,9 +70,12 @@ router.get('/', async function (req, res, next) { }); router.get('/pageinfo', async function (req, res, next) { - const today_visited = await leancloud.danmakuQuery(leancloud.currentDay()); - const lastday_visited = await leancloud.danmakuQuery(leancloud.lastDay()); - const month_visited = await leancloud.danmakuQuery(leancloud.currentMonth()); + const promises = [ + leancloud.danmakuQuery(leancloud.currentDay()), + leancloud.danmakuQuery(leancloud.lastDay()), + leancloud.danmakuQuery(leancloud.currentMonth()) + ] + const [today_visited, lastday_visited, month_visited] = await Promise.all(promises) res.json({today_visited, lastday_visited, month_visited}) }); diff --git a/utils/leancloud.js b/utils/leancloud.js index 12bc59d..b9a80fe 100644 --- a/utils/leancloud.js +++ b/utils/leancloud.js @@ -33,7 +33,7 @@ function currentDay() { const date = new Date(); const start = new Date(date.setHours(0, 0, 0, 0)) const end = new Date(date.setHours(23, 59, 59, 999)) - return [start,end] + return [start, end] } function lastDay() { @@ -55,11 +55,21 @@ async function danmakuQuery(date) { query.greaterThanOrEqualTo('createdAt', date[0]); query.lessThan('createdAt', date[1]); - // query.exists('url'); + query.exists('url'); return await query.count() } -module.exports = {danmakuAccessAdd, danmakuQuery, currentDay, currentMonth, lastDay}; +function danmakuErrorAdd(obj) { + const {ip, url, error} = obj; + const DanmakuErrorObject = AV.Object.extend('DanmakuError'); + const record = new DanmakuErrorObject(); + record.set('remoteIP', ip); + record.set('url', url); + record.set('error', JSON.stringify(error)); + record.save().then() +} + +module.exports = {danmakuAccessAdd, danmakuQuery, currentDay, currentMonth, lastDay, danmakuErrorAdd}; if (!module.parent) { } diff --git a/views/danmaku.ejs b/views/danmaku.ejs index 4b72651..c9c9e34 100644 --- a/views/danmaku.ejs +++ b/views/danmaku.ejs @@ -86,9 +86,9 @@
- 今日访问量: | - 昨日访问量: | - 当月访问量: + 今日解析量: | + 昨日解析量: | + 当月解析量: