fix: 限制旧内存部分的最大内存大小为200M,增加测试用例

This commit is contained in:
lyz05
2022-11-08 17:09:06 +08:00
parent 02eb6d6821
commit b7eb2d238e
7 changed files with 30 additions and 9 deletions

View File

@@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "node --max-old-space-size=128 ./bin/www",
"dev": "nodemon --max-old-space-size=128 ./bin/www",
"start": "node --max-old-space-size=200 ./bin/www",
"dev": "nodemon --max-old-space-size=200 ./bin/www",
"test": "nyc -a mocha --recursive"
},
"dependencies": {

View File

@@ -8,7 +8,8 @@ function Iqiyi() {
this.name = '爱奇艺'
this.domain = 'iqiyi.com'
this.example_urls = [
'https://www.iqiyi.com/v_19rr1lm35o.html'
'https://www.iqiyi.com/v_19rr1lm35o.html', //api lens 11
'https://www.iqiyi.com/v_1wozsa91cfs.html' //api lens 9
];
this.resolve = async (url) => {

View File

@@ -9,7 +9,8 @@ function Tencentvideo() {
this.domain = 'v.qq.com'
this.example_urls = [
'https://v.qq.com/x/cover/mzc002003pn34qk/u3319i5s3jt.html',
'https://v.qq.com/x/cover/53q0eh78q97e4d1/x00174aq5no.html'//api lens 50
'https://v.qq.com/x/cover/53q0eh78q97e4d1/x00174aq5no.html',//api lens 50
'https://v.qq.com/x/cover/mzc00200fph94nw/l00448ijvve.html',//api lens 91
];
this.resolve = async (url) => {

View File

@@ -9,7 +9,8 @@ function Youku() {
this.name = '优酷'
this.domain = 'v.youku.com'
this.example_urls = [
'https://v.youku.com/v_show/id_XNTE5NjUxNjUyOA==.html'
'https://v.youku.com/v_show/id_XNTE5NjUxNjUyOA==.html',
'https://v.youku.com/v_show/id_XMTc1OTE4ODI5Ng==.html'
];
this.get_tk_enc = async () => {

View File

@@ -1,14 +1,15 @@
const express = require('express');
const axios = require('axios');
const router = express.Router();
const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('../routes/api/base');
const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('./api/base');
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
const memory = require('../utils/memory')
function getscheme(req) {
return req.headers['x-forwarded-proto'] || req.protocol;
}
async function build_response(url, download) {
async function build_response(url) {
try {
const res = await axios.get(url)
} catch (error) {
@@ -37,7 +38,8 @@ router.get('/', async function (req, res, next) {
} else {
url = req.query.url;
download = (req.query.download === 'on');
ret = await build_response(url, download)
ret = await build_response(url)
memory() //显示内存使用量
if (ret.msg !== 'ok') {
res.status(403).send(ret.msg)
} else if (download) {

View File

@@ -4,7 +4,6 @@ let app = require('../app');
const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('../routes/api/base');
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
let should = chai.should();
chai.use(chaiHttp);
describe('App', () => {
@@ -77,4 +76,7 @@ describe('App', () => {
});
});
});
describe('airportsub modules',()=>{
});
});

14
utils/memory.js Normal file
View File

@@ -0,0 +1,14 @@
const {filesize} = require('filesize')
const print = function () {
const memoryUsage = process.memoryUsage();
console.log(JSON.stringify({
rss: filesize(memoryUsage.rss),//RAM 中保存的进程占用的内存部分,包括代码本身、栈、堆。
heapTotal: filesize(memoryUsage.heapTotal),//堆中总共申请到的内存量。
heapUsed: filesize(memoryUsage.heapUsed),//堆中目前用到的内存量,判断内存泄漏我们主要以这个字段为准。
external: filesize(memoryUsage.external),// V8 引擎内部的 C++ 对象占用的内存。
}));
}
module.exports = print