Skip to content

Commit 082a59a

Browse files
author
Taois
committed
feat: 优化日志输出,允许屏蔽自建解析
1 parent 044ea17 commit 082a59a

File tree

12 files changed

+150
-162
lines changed

12 files changed

+150
-162
lines changed

controllers/config.js

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -660,78 +660,82 @@ async function generateSiteJSON(options, requestHost, sub, pwd) {
660660
* @returns {Promise<Object>} 包含parses数组的对象
661661
*/
662662
async function generateParseJSON(jxDir, requestHost) {
663-
const files = readdirSync(jxDir);
664-
const jx_files = files.filter((file) => file.endsWith('.js') && !file.startsWith('_')) // 筛选出不是 "_" 开头的 .js 文件
665-
const jx_dict = getParsesDict(requestHost);
663+
let enable_self_jx = ENV.get('enable_self_jx', '0') === '1';
666664
let parses = [];
667-
const tasks = jx_files.map((file) => {
668-
return {
669-
func: async ({file, jxDir, requestHost, drpyS}) => {
670-
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
671-
const api = `${requestHost}/parse/${baseName}?url=`; // 使用请求的 host 地址,避免硬编码端口
672-
673-
let jxObject = {
674-
type: 1, // 固定值
675-
ext: {
676-
flag: [
677-
"qiyi",
678-
"imgo",
679-
"爱奇艺",
680-
"奇艺",
681-
"qq",
682-
"qq 预告及花絮",
683-
"腾讯",
684-
"youku",
685-
"优酷",
686-
"pptv",
687-
"PPTV",
688-
"letv",
689-
"乐视",
690-
"leshi",
691-
"mgtv",
692-
"芒果",
693-
"sohu",
694-
"xigua",
695-
"fun",
696-
"风行"
697-
]
698-
},
699-
header: {
700-
"User-Agent": "Mozilla/5.0"
665+
let sorted_parses = [];
666+
const jx_dict = getParsesDict(requestHost);
667+
if (enable_self_jx) {
668+
const files = readdirSync(jxDir);
669+
const jx_files = files.filter((file) => file.endsWith('.js') && !file.startsWith('_')) // 筛选出不是 "_" 开头的 .js 文件
670+
const tasks = jx_files.map((file) => {
671+
return {
672+
func: async ({file, jxDir, requestHost, drpyS}) => {
673+
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
674+
const api = `${requestHost}/parse/${baseName}?url=`; // 使用请求的 host 地址,避免硬编码端口
675+
676+
let jxObject = {
677+
type: 1, // 固定值
678+
ext: {
679+
flag: [
680+
"qiyi",
681+
"imgo",
682+
"爱奇艺",
683+
"奇艺",
684+
"qq",
685+
"qq 预告及花絮",
686+
"腾讯",
687+
"youku",
688+
"优酷",
689+
"pptv",
690+
"PPTV",
691+
"letv",
692+
"乐视",
693+
"leshi",
694+
"mgtv",
695+
"芒果",
696+
"sohu",
697+
"xigua",
698+
"fun",
699+
"风行"
700+
]
701+
},
702+
header: {
703+
"User-Agent": "Mozilla/5.0"
704+
}
705+
};
706+
try {
707+
let _jxObject = await drpyS.getJx(path.join(jxDir, file));
708+
jxObject = {...jxObject, ..._jxObject};
709+
} catch (e) {
710+
throw new Error(`Error parsing jx object for file: ${file}, ${e.message}`);
701711
}
702-
};
703-
try {
704-
let _jxObject = await drpyS.getJx(path.join(jxDir, file));
705-
jxObject = {...jxObject, ..._jxObject};
706-
} catch (e) {
707-
throw new Error(`Error parsing jx object for file: ${file}, ${e.message}`);
708-
}
709712

710-
parses.push({
711-
name: baseName,
712-
url: jxObject.url || api,
713-
type: jxObject.type,
714-
ext: jxObject.ext,
715-
header: jxObject.header
716-
});
713+
parses.push({
714+
name: baseName,
715+
url: jxObject.url || api,
716+
type: jxObject.type,
717+
ext: jxObject.ext,
718+
header: jxObject.header
719+
});
720+
},
721+
param: {file, jxDir, requestHost, drpyS},
722+
id: file,
723+
};
724+
});
725+
726+
const listener = {
727+
func: (param, id, error, result) => {
728+
if (error) {
729+
console.error(`Error processing file ${id}:`, error.message);
730+
} else {
731+
// console.log(`Successfully processed file ${id}:`, result);
732+
}
717733
},
718-
param: {file, jxDir, requestHost, drpyS},
719-
id: file,
734+
param: {}, // 外部参数可以在这里传入
720735
};
721-
});
722-
723-
const listener = {
724-
func: (param, id, error, result) => {
725-
if (error) {
726-
console.error(`Error processing file ${id}:`, error.message);
727-
} else {
728-
// console.log(`Successfully processed file ${id}:`, result);
729-
}
730-
},
731-
param: {}, // 外部参数可以在这里传入
732-
};
733-
await batchExecute(tasks, listener);
734-
let sorted_parses = naturalSort(parses, 'name', ['JSON并发', 'JSON合集', '虾米', '奇奇']);
736+
await batchExecute(tasks, listener);
737+
sorted_parses = naturalSort(parses, 'name', ['JSON并发', 'JSON合集', '虾米', '奇奇']);
738+
}
735739
let sorted_jx_dict = naturalSort(jx_dict, 'name', ['J', 'W']);
736740
parses = sorted_parses.concat(sorted_jx_dict);
737741
return {parses};

controllers/fastlogger.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ dotenv.config();
1111
const LOG_WITH_FILE = Number(process.env.LOG_WITH_FILE) || 0;
1212
const LOG_LEVEL = process.env.LOG_LEVEL && ['trace', 'debug', 'info', 'warn', 'error', 'fatal'].includes(process.env.LOG_LEVEL) ? process.env.LOG_LEVEL : 'info';
1313
const COOKIE_AUTH_CODE = process.env.COOKIE_AUTH_CODE || 'drpys';
14-
console.log('LOG_WITH_FILE:', LOG_WITH_FILE);
15-
console.log('LOG_LEVEL:', LOG_LEVEL);
16-
console.log('COOKIE_AUTH_CODE:', COOKIE_AUTH_CODE);
14+
// console.log('LOG_WITH_FILE:', LOG_WITH_FILE);
15+
// console.log('LOG_LEVEL:', LOG_LEVEL);
16+
// console.log('COOKIE_AUTH_CODE:', COOKIE_AUTH_CODE);
1717
let _logger = true;
1818
let logStream = null;
1919

controllers/index.js

Lines changed: 50 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,59 @@
1-
/**
2-
* 控制器路由注册模块
3-
* 统一管理和注册所有控制器路由
4-
* 提供应用程序的所有API端点和功能模块
5-
*/
61
import formBody from '@fastify/formbody';
72
import websocket from '@fastify/websocket';
3+
import websocketController from './websocket.js';
4+
import staticController from './static.js';
5+
import docsController from './docs.js';
6+
import configController from './config.js';
7+
import apiController from './api.js';
8+
import mediaProxyController from './mediaProxy.js';
9+
import rootController from './root.js';
10+
import encoderController from './encoder.js';
11+
import decoderController from './decoder.js';
12+
import authcoderController from './authcoder.js';
13+
import webController from './web.js';
14+
import httpController from './http.js';
15+
import clipboardPusherController from './clipboard-pusher.js';
16+
// import taskerController from './tasker.js';
17+
import cronTaskerController from './cron-tasker.js';
18+
import sourceCheckerController from './source-checker.js';
19+
import imageStoreController from './image-store.js';
20+
import webdavProxyController from './webdav-proxy.js';
21+
import ftpProxyController from './ftp-proxy.js';
22+
import fileProxyController from './file-proxy.js';
23+
import m3u8ProxyController from './m3u8-proxy.js';
24+
import unifiedProxyController from './unified-proxy.js';
25+
import githubController from './github.js';
26+
import websocketServerController from "./websocketServer.js";
827

9-
// 懒加载辅助函数
10-
const lazyRegister = (fastify, importFn, options) => {
11-
fastify.register(async (instance, opts) => {
12-
const module = await importFn();
13-
const plugin = module.default || module;
14-
// 使用传入的 options (全局配置)
15-
await instance.register(plugin, options);
16-
});
17-
};
18-
19-
/**
20-
* 注册所有路由控制器
21-
* 将各个功能模块的路由注册到Fastify实例中
22-
* @param {Object} fastify - Fastify应用实例
23-
* @param {Object} options - 路由配置选项
24-
*/
2528
export const registerRoutes = (fastify, options) => {
26-
// 注册插件以支持 application/x-www-form-urlencoded
2729
fastify.register(formBody);
28-
// 注册WebSocket插件
2930
fastify.register(websocket);
30-
31-
// WebSocket实时日志控制器-最早引入才能全局拦截console日志
32-
lazyRegister(fastify, () => import('./websocket.js'), options);
33-
// 静态文件服务控制器
34-
lazyRegister(fastify, () => import('./static.js'), options);
35-
// 文档服务控制器
36-
lazyRegister(fastify, () => import('./docs.js'), options);
37-
// 配置管理控制器
38-
lazyRegister(fastify, () => import('./config.js'), options);
39-
// API接口控制器
40-
lazyRegister(fastify, () => import('./api.js'), options);
41-
// 媒体代理控制器
42-
lazyRegister(fastify, () => import('./mediaProxy.js'), options);
43-
// 根路径控制器
44-
lazyRegister(fastify, () => import('./root.js'), options);
45-
// 编码器控制器
46-
lazyRegister(fastify, () => import('./encoder.js'), options);
47-
// 解码器控制器
48-
lazyRegister(fastify, () => import('./decoder.js'), options);
49-
// 认证编码控制器
50-
lazyRegister(fastify, () => import('./authcoder.js'), options);
51-
// Web界面控制器
52-
lazyRegister(fastify, () => import('./web.js'), options);
53-
// HTTP请求控制器
54-
lazyRegister(fastify, () => import('./http.js'), options);
55-
// 剪贴板推送控制器
56-
lazyRegister(fastify, () => import('./clipboard-pusher.js'), options);
57-
// 任务控制器(已注释)
58-
// lazyRegister(fastify, () => import('./tasker.js'), options);
59-
// 定时任务控制器
60-
lazyRegister(fastify, () => import('./cron-tasker.js'), options);
61-
// 源检查控制器
62-
lazyRegister(fastify, () => import('./source-checker.js'), options);
63-
// 图片存储控制器
64-
lazyRegister(fastify, () => import('./image-store.js'), options);
65-
// WebDAV 代理控制器
66-
lazyRegister(fastify, () => import('./webdav-proxy.js'), options);
67-
// FTP 代理控制器
68-
lazyRegister(fastify, () => import('./ftp-proxy.js'), options);
69-
// 文件代理控制器
70-
lazyRegister(fastify, () => import('./file-proxy.js'), options);
71-
lazyRegister(fastify, () => import('./m3u8-proxy.js'), options);
72-
// 注册统一代理路由
73-
lazyRegister(fastify, () => import('./unified-proxy.js'), options);
74-
// 注册GitHub Release路由
75-
lazyRegister(fastify, () => import('./github.js'), options);
31+
32+
fastify.register(websocketController, options);
33+
fastify.register(staticController, options);
34+
fastify.register(docsController, options);
35+
fastify.register(configController, options);
36+
fastify.register(apiController, options);
37+
fastify.register(mediaProxyController, options);
38+
fastify.register(rootController, options);
39+
fastify.register(encoderController, options);
40+
fastify.register(decoderController, options);
41+
fastify.register(authcoderController, options);
42+
fastify.register(webController, options);
43+
fastify.register(httpController, options);
44+
fastify.register(clipboardPusherController, options);
45+
// fastify.register(taskerController, options);
46+
fastify.register(cronTaskerController, options);
47+
fastify.register(sourceCheckerController, options);
48+
fastify.register(imageStoreController, options);
49+
fastify.register(webdavProxyController, options);
50+
fastify.register(ftpProxyController, options);
51+
fastify.register(fileProxyController, options);
52+
fastify.register(m3u8ProxyController, options);
53+
fastify.register(unifiedProxyController, options);
54+
fastify.register(githubController, options);
7655
};
7756

78-
/**
79-
* 注册弹幕路由控制器
80-
* 将弹幕功能模块的路由注册到Fastify实例中
81-
* @param {Object} wsApp - Ws实时弹幕预览应用实例
82-
* @param {Object} options - 路由配置选项
83-
*/
8457
export const registerWsRoutes = (wsApp, options) => {
85-
lazyRegister(wsApp, () => import("./websocketServer.js"), options);
86-
}
58+
wsApp.register(websocketServerController, options);
59+
};

libs/catvod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const _config_path = path.join(__dirname, '../config');
1414
const _lib_path = path.join(__dirname, '../spider/catvod');
1515
const enable_cat_debug = Number(process.env.CAT_DEBUG) !== 2;
1616

17-
console.log('enable_cat_debug:', enable_cat_debug);
17+
// console.log('enable_cat_debug:', enable_cat_debug);
1818

1919
const json2Object = function (json) {
2020
if (!json) {

libs_drpy/req-extend.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ async function request(url, obj = {}, ocr_flag = false) {
4040
obj.headers["Content-Type"] = 'text/html; charset=' + rule.encoding;
4141
}
4242
}
43+
if (rule.timeout && typeof obj.timeout === 'undefined') {
44+
obj.timeout = rule.timeout;
45+
}
4346
if (typeof (obj.body) != 'undefined' && obj.body && typeof (obj.body) === 'string') {
4447
// 传body加 "Content-Type":"application/x-www-form-urlencoded;" 即可post form
4548
if (!obj.headers.hasOwnProperty('Content-Type') && !obj.headers.hasOwnProperty('content-type')) { // 手动指定了就不管
@@ -75,7 +78,7 @@ async function request(url, obj = {}, ocr_flag = false) {
7578
// }
7679

7780
log(`[request] headers: ${JSON.stringify(obj.headers)}`);
78-
log('[request] url:' + url + ` |method:${obj.method || 'GET'} |body:${obj.body || ''}`);
81+
log('[request] url:' + url + ` |method:${obj.method || 'GET'}|timeout:${obj.timeout} |body:${obj.body || ''}`);
7982
let res = await req(url, obj);
8083
let html = res.content || '';
8184
if (obj.withHeaders) {

spider/js/番茄小说[书].js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const {getRandomFromList} = $.require('./_lib.random.js');
2424
const {requestHtml} = $.require('./_lib.request.js');
2525
// const fqweb_host = 'http://fqweb.jsj66.com';
2626
// const fqweb_host = 'http://fanqie.mduge.com';
27-
const fqweb_host = 'https://qkfqapi.vv9v.cn';
27+
// const fqweb_host = 'https://qkfqapi.vv9v.cn';
28+
const fqweb_host = 'http://101.35.133.34:5000';
2829
// const fqweb_host = 'http://101.35.133.34:5000/docs'; //备选
2930
// const fqweb_host = 'http://103.236.91.147:9999/docs'; //备选
3031
// const fqweb_host = 'http://47.108.80.161:5005/docs'; //备选
@@ -62,7 +63,7 @@ var rule = {
6263
api: 'https://novel.snssdk.com/api',
6364
封面域名: 'http://p6-novel.byteimg.com/large/',
6465
},
65-
timeout: 5000,
66+
timeout: 20000,
6667
play_parse: true,
6768
class_parse: async () => {
6869
// let html = (await req(rule.homeUrl)).content;
@@ -208,7 +209,8 @@ var rule = {
208209
content = content.replace(/<\/p>/g, '\n').replace(/<\w+>/g, '').replace(/<[^>]*>/g, '');
209210
*/
210211

211-
let html = (await req(content_url, {headers: {Cookie: getFqCookie()}})).content;
212+
// let html = (await req(content_url, {headers: {Cookie: getFqCookie()},timeout:this.timeout})).content;
213+
let html = await request(content_url);
212214
/*
213215
let json = JSON.parse(html).data.data;
214216
title = json.novel_data.title;

spider/js/番茄漫画[画].js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
var rule = {
1414
类型: '漫画',
1515
title: '番茄漫画',
16-
host: 'https://qkfqapi.vv9v.cn',
16+
// host: 'https://qkfqapi.vv9v.cn',
17+
host: 'http://47.108.80.161:5005',
1718
homeUrl: '/api/discover/style?tab=漫画',
1819
url: 'fyclass',
1920
searchUrl: '/api/search?key=**&tab_type=8&offset=((fypage-1)*10)',
@@ -39,10 +40,10 @@ var rule = {
3940
return {class: d}
4041
},
4142
lazy: async function () {
42-
let {input, pdfa, pdfh} = this;
43+
let {input, pdfa, pdfh, HOST} = this;
4344
let title = input.split('@')[1];
4445
input = input.split('@')[0];
45-
let content_url = `https://qkfqapi.vv9v.cn/api/content?tab=漫画&item_id=${input}&show_html=0`; // 正文获取接口
46+
let content_url = `${HOST}/api/content?tab=漫画&item_id=${input}&show_html=0`; // 正文获取接口
4647
let jsonStr = await request(content_url);
4748
let images = jsonStr.parseX.data.images;
4849
images = pdfa(images, 'img');
@@ -82,7 +83,7 @@ var rule = {
8283
return this.parseList(html);
8384
},
8485
二级: async function () {
85-
let {input, orId} = this;
86+
let {input, orId, HOST} = this;
8687
let html = await request(input);
8788
let data = html.parseX.data.data;
8889
let VOD = {};
@@ -96,7 +97,7 @@ var rule = {
9697
VOD.vod_actor = '';
9798
VOD.vod_director = data.author;
9899
VOD.vod_play_from = '番茄漫画';
99-
let jsonStr = await request(`https://qkfqapi.vv9v.cn/api/book?book_id=${orId}`);
100+
let jsonStr = await request(`${HOST}/api/book?book_id=${orId}`);
100101
let book_info = jsonStr.parseX.data.data;
101102
let list = book_info.chapterListWithVolume.flat();
102103
let urls = [];

0 commit comments

Comments
 (0)