Skip to content

Commit 307d700

Browse files
author
Taois
committed
feat: 支持php的t3格式
1 parent 5c4e88e commit 307d700

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

controllers/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,20 +496,20 @@ async function generateSiteJSON(options, requestHost, sub, pwd) {
496496
// 根据用户是否启用php源去生成对应配置
497497
const enable_php = ENV.get('enable_php', '1');
498498
console.log('isPhpAvailable:', isPhpAvailable);
499-
if (enable_php === '1' && isPhpAvailable) {
499+
if ((enable_php === '1' && isPhpAvailable) || enable_php === '2') {
500500
const php_files = readdirSync(phpDir);
501-
const api_type = 4;
501+
const api_type = enable_php === '2' ? 3 : 4;
502502
let php_valid_files = php_files.filter((file) => file.endsWith('.php') && !file.startsWith('_') && !['config.php', 'index.php', 'test_runner.php'].includes(file));
503503
log(`开始生成php的T${api_type}配置,phpDir:${phpDir},源数量: ${php_valid_files.length}`);
504504

505505
const php_tasks = php_valid_files.map((file) => {
506506
return {
507507
func: async ({file, phpDir, requestHost, pwd, SitesMap}) => {
508508
const baseName = path.basename(file, '.php');
509-
let api = `${requestHost}/api/${baseName}?do=php`;
509+
let api = enable_php === '2' ? `${requestHost}/php/${file}` : `${requestHost}/api/${baseName}?do=php`;
510510
let ext = '';
511511
if (pwd) {
512-
api += `&pwd=${pwd}`;
512+
api += enable_php === '2' ? `?pwd=${pwd}` : `&pwd=${pwd}`;
513513
}
514514
let ruleObject = {
515515
searchable: 1,

controllers/static.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ export default (fastify, options, done) => {
7979
}
8080
});
8181

82+
// 注册PHP脚本文件服务 - 用于存放PHP相关的脚本文件
83+
fastify.register(fastifyStatic, {
84+
root: options.phpDir, // PHP脚本根目录
85+
prefix: '/php/', // URL访问前缀
86+
decorateReply: false, // 禁用 sendFile 装饰器
87+
setHeaders: (res, path) => {
88+
// 为PHP文件设置正确的Content-Type,确保浏览器以纯文本形式显示
89+
if (path.endsWith('.php')) {
90+
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
91+
}
92+
}
93+
});
94+
8295
// 注册CAT相关文件服务 - 用于存放CAT视频源相关文件
8396
fastify.register(fastifyStatic, {
8497
root: options.catDir, // CAT文件根目录

docs/envdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
| 参数键 | 参数说明 | 备注 |
4444
| :--- | :--- | :--- |
45-
| enable_php | 是否开启 PHP 源支持 | 0:关闭 1:开启 (默认开启,需 PHP 环境可用) |
45+
| enable_php | 是否开启 PHP 源支持 | 0:关闭 1:开启(本地执行T4,需环境) 2:开启(远程加载T3,免环境) |
4646
| api_pwd | 全局接口访问密码 | 访问敏感接口或文件时需要 |
4747
| thread | 爬虫并发数 | 建议设置在 4-8 之间 |
4848
| quark_cookie | 夸克网盘 Cookie | 观看夸克网盘资源需要 |

0 commit comments

Comments
 (0)