Skip to content

Commit 59e28d8

Browse files
author
Taois
committed
feat: 修复了一些源,支持了猫源导入依赖
1 parent d943879 commit 59e28d8

22 files changed

+6520
-25
lines changed

.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ QQ_EMAIL =
3333
QQ_SMTP_AUTH_CODE =
3434

3535
# 调试猫源
36-
CAT_DEBUG=0
36+
CAT_DEBUG=1

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# drpyS(drpy-node)
22

33
nodejs作为服务端的drpy实现。全面升级异步写法
4-
~~积极开发中,每日一更~~,当前进度 `73%`
4+
~~积极开发中,每日一更~~,当前进度 `75%`
55
~~找工作中,随缘更新~~
66
上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新
77

@@ -24,6 +24,10 @@ nodejs作为服务端的drpy实现。全面升级异步写法
2424

2525
## 更新记录
2626

27+
### 20250815
28+
29+
更新至V1.2.12
30+
2731
### 20250814
2832

2933
更新至V1.2.11

controllers/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export default (fastify, options, done) => {
184184
...resultHome,
185185
// list: resultHomeVod,
186186
};
187+
// console.log('resultHomeVod:',resultHomeVod);
187188
if (Array.isArray(resultHomeVod) && resultHomeVod.length > 0) {
188189
Object.assign(result, {list: resultHomeVod})
189190
}

docs/updateRecord.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# drpyS更新记录
22

3+
### 20250815
4+
5+
更新至V1.2.12
6+
7+
关键更新说明: 前面版本不支持cat源内import其他依赖,相对路径都不支持更别说 assets开头的了。
8+
此版本解决了,用法跟壳子一样,支持`assets://`(映射到spider/catLib) 和相对路径 `./` `../`开头的依赖
9+
10+
1. 修复 `番茄小说` 分类 by 二群 `ƪ(˘⌣˘)ʃ优雅`
11+
2. 修复 `抖音弹幕直播` by 二群 `ƪ(˘⌣˘)ʃ优雅`
12+
3. catvod猫源支持import assets开头依赖,ds非调试模式下已经补齐依赖。
13+
4. 增加 `esm-register.mjs` 通过拦截import导入的esm模块,实现猫源的 `assets:` 导入识别,路径映射到 `spider/catLib`
14+
5. 增加 cat源 `河南电视代理.js` 用于演示正确的猫源本代写法。action也支持。
15+
6. 修复猫源T4首页推荐数据问题。
16+
317
### 20250814
418

519
更新至V1.2.11
@@ -8,7 +22,8 @@
822
2. `cat源` 增加调试模式,但是不支持 `getProxyUrl` 等方法,需要在环境变量.env文件里启用 `CAT_DEBUG=1`
923
详情参考 [猫源调试教程](/docs/catDebug.md)
1024
3. `getProxyUrl` 换成 `getProxy`,兼容T3猫源使用壳子的本地代理,修复 `央视大全` 错误的本地代理获取
11-
4. 修复`番茄小说` 的正文阅读和搜索。分类接口坏的没能力修。央视最新视频高清下载方案目前只有通过 [`CCTV-GO`](https://wwvy.lanzouo.com/ieEq533kiofe) 包含的 `cbox.exe` 本地解密,无法适配本项目。
25+
4. 修复`番茄小说` 的正文阅读和搜索。分类接口坏的没能力修。央视最新视频高清下载方案目前只有通过 [
26+
`CCTV-GO`](https://wwvy.lanzouo.com/ieEq533kiofe) 包含的 `cbox.exe` 本地解密,无法适配本项目。
1227

1328
### 20250813
1429

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import qs from 'qs';
66
import {fileURLToPath} from 'url';
77
import formBody from '@fastify/formbody';
88
import {validateBasicAuth, validateJs, validatePwd} from "./utils/api_validate.js";
9+
// 注册自定义import钩子
10+
import './utils/esm-register.mjs';
911
// 注册控制器
1012
import {registerRoutes} from './controllers/index.js';
1113

libs/catvod.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,56 @@ const json2Object = function (json) {
2525
return JSON.parse(json);
2626
}
2727

28-
const loadEsmWithHash = async function (filePath, fileHash) {
28+
const loadEsmWithHash = async function (filePath, fileHash, env) {
2929
const scriptUrl = `${pathToFileURL(filePath).href}?v=${fileHash}`;
30-
return await import(scriptUrl);
30+
const module = await import(scriptUrl);
31+
const initEnv = module.initEnv;
32+
if (typeof initEnv === 'function' && env) {
33+
initEnv(env);
34+
}
35+
return module
3136
}
3237

3338
const loadEsmWithEnv = async function (filePath, env) {
3439
const rawCode = await readFile(filePath, 'utf8');
3540
let injectedCode = rawCode;
41+
// let injectedCode = rawCode.replaceAll('assets://js/lib/', '../catLib/'); // esm-rregister处理了,这里不管
42+
// console.log('loadEsmWithEnv:', env);
3643
const esm_flag1 = 'export function __jsEvalReturn';
3744
const esm_flag2 = 'export default';
3845
const polyfill_code = `
3946
var _ENV={};
4047
var getProxyUrl=null;
4148
var getProxy=null;
42-
export const initEnv = (env)=>{
49+
export function initEnv(env){
4350
_ENV = env;
4451
if(env.getProxyUrl){
4552
getProxyUrl=env.getProxyUrl;
4653
getProxy=env.getProxyUrl
4754
}
48-
};`.trim() + '\n';
49-
if (rawCode.includes(esm_flag1)) {
50-
injectedCode = rawCode.replace(esm_flag1, `${polyfill_code}${esm_flag1}`)
51-
} else if (rawCode.includes('export default')) {
52-
injectedCode = rawCode.replace(esm_flag2, `${polyfill_code}${esm_flag2}`)
55+
}`.trim() + '\n';
56+
if (injectedCode.includes(esm_flag1)) {
57+
injectedCode = injectedCode.replace(esm_flag1, `${polyfill_code}${esm_flag1}`)
58+
} else if (injectedCode.includes('export default')) {
59+
injectedCode = injectedCode.replace(esm_flag2, `${polyfill_code}${esm_flag2}`)
5360
}
54-
// console.log(injectedCode);
61+
62+
// 改为在 esm-register.mjs 里实现,这里注释掉
63+
// if (injectedCode.includes('../catLib/crypto-js.js')) {
64+
// const cryptoJsPath = path.join(_lib_path, '../catLib', 'crypto-js.js');
65+
// // console.log('cryptoJsPath:',cryptoJsPath);
66+
// const cryptoHref = pathToFileURL(cryptoJsPath).href;
67+
// console.log('cryptoHref:', cryptoHref);
68+
// // const cryptoJsCode = await readFile(cryptoJsPath, 'utf-8');
69+
// // const cryptoJsBase64 = Buffer.from(cryptoJsCode).toString('base64');
70+
// injectedCode = injectedCode.replace(
71+
// '../catLib/crypto-js.js',
72+
// // `data:text/javascript;base64,${cryptoJsBase64}`
73+
// cryptoHref
74+
// );
75+
// }
76+
77+
// console.log('injectedCode:\n', injectedCode);
5578
// // 创建数据URI模块
5679
const dataUri = `data:text/javascript;base64,${Buffer.from(injectedCode).toString('base64')}`;
5780
const module = await import(dataUri);
@@ -73,6 +96,12 @@ const init = async function (filePath, env = {}, refresh) {
7396
const fileHash = computeHash(fileContent);
7497
const moduleName = path.basename(filePath, '.js');
7598
let moduleExt = env.ext || '';
99+
const default_init_cfg = {
100+
stype: 4, //T3/T4 源类型
101+
skey: `catvod_${moduleName}`,
102+
sourceKey: `catvod_${moduleName}`,
103+
ext: moduleExt,
104+
};
76105
let SitesMap = getSitesMap(_config_path);
77106
if (moduleExt && SitesMap[moduleName]) {
78107
try {
@@ -96,7 +125,7 @@ const init = async function (filePath, env = {}, refresh) {
96125
let t1 = getNowTime();
97126
let module;
98127
if (enable_cat_debug) {
99-
module = await loadEsmWithHash(filePath, fileHash);
128+
module = await loadEsmWithHash(filePath, fileHash, env);
100129
} else {
101130
module = await loadEsmWithEnv(filePath, env);
102131
}
@@ -111,7 +140,7 @@ const init = async function (filePath, env = {}, refresh) {
111140
// console.log('globalThis.ENV:', globalThis.ENV);
112141
// console.log('globalThis.getProxyUrl:', globalThis.getProxyUrl);
113142
// 加载 init
114-
await rule.init(moduleExt || {});
143+
await rule.init(default_init_cfg);
115144
let t2 = getNowTime();
116145
const moduleObject = deepCopy(rule);
117146
moduleObject.cost = t2 - t1;
@@ -130,7 +159,8 @@ const home = async function (filePath, env, filter = 1) {
130159

131160
const homeVod = async function (filePath, env) {
132161
const moduleObject = await init(filePath, env);
133-
return json2Object(await moduleObject.homeVod());
162+
const homeVodResult = json2Object(await moduleObject.homeVod());
163+
return homeVodResult && homeVodResult.list ? homeVodResult.list : homeVodResult;
134164
}
135165

136166

libs_drpy/drpyInject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axiosX from './axios.min.js';
33
import crypto from 'crypto';
44
import http from "http";
55
import https from 'https';
6-
import fs from 'node:fs';
6+
import fs from 'fs';
77
import qs from 'qs';
88
import _ from './underscore-esm.min.js'
99
// import _ from './underscore-esm.js'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "drpy-node",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
77
"build": "node index.js",
88
"dev": "node index.js",
99
"dev-win": "chcp 65001 && node --trace-deprecation index.js",
1010
"dev-win-debug": "chcp 65001 && node --trace-deprecation --inspect index.js",
11+
"dev-win-debug2": "chcp 65001 && node --trace-deprecation --inspect --experimental-loader ./utils/esm-loader.mjs index.js",
1112
"pm2": "pm2 start index.js --name drpys",
1213
"node22": "node --experimental-sqlite index.js",
1314
"node22-win": "chcp 65001 && node --trace-deprecation --experimental-sqlite index.js",

public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</head>
99
<body>
1010
<h1 id="drpysdrpy-node">drpyS(drpy-node)</h1>
11-
<p>nodejs作为服务端的drpy实现。全面升级异步写法<br><del>积极开发中,每日一更</del>,当前进度 <code>72%</code><br><del>找工作中,随缘更新</del><br>上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新</p>
11+
<p>nodejs作为服务端的drpy实现。全面升级异步写法<br><del>积极开发中,每日一更</del>,当前进度 <code>75%</code><br><del>找工作中,随缘更新</del><br>上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新</p>
1212
<ul>
1313
<li><a href="docs/apidoc.md">接口文档</a> | <a href="docs/apiList.md">接口列表如定时任务</a> | <a href="https://github.com/waifu-project/movie/pull/135">小猫影视-待对接T4</a></li>
1414
<li><a href="/config?pwd=dzyyds">本地配置接口-动态本地</a></li>
@@ -28,6 +28,8 @@ <h1 id="drpysdrpy-node">drpyS(drpy-node)</h1>
2828
<li><a href="/cat/index.html">在线猫ds源主页</a></li>
2929
</ul>
3030
<h2 id="更新记录">更新记录</h2>
31+
<h3 id="20250815">20250815</h3>
32+
<p>更新至V1.2.12</p>
3133
<h3 id="20250814">20250814</h3>
3234
<p>更新至V1.2.11</p>
3335
<h3 id="20250813">20250813</h3>

spider/catLib/cat.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)