Skip to content

Create build-nodejs.yml #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/build-nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build NodeJS

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.17.1

- name: Run npm bild
working-directory: nodejs
run: |
npm i
npm run build

- name: Archive dist
uses: actions/upload-artifact@v4
with:
name: dist
path: |
nodejs/dist
21 changes: 11 additions & 10 deletions nodejs/copyDist.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// Import required modules
// 新添加用于支持DS源适配猫影视
// 导入所需模块
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';

// Check if the destination path is provided
// 检查是否提供了目标路径
if (process.argv.length < 3) {
console.error('Usage: node script.js <destination_path>');
process.exit(1);
}

// Get the destination path from command-line arguments
// 从命令行参数获取目标路径
const destinationPath = process.argv[2];

// Resolve paths
// 解析路径
const distPath = path.resolve(process.cwd(), 'dist');
const targetPath = path.resolve(destinationPath);

// Check if dist directory exists
// 检查dist目录是否存在
if (!fs.existsSync(distPath)) {
console.error(`Source directory does not exist: ${distPath}`);
process.exit(1);
}

// Check if target directory exists
// 检查目标目录是否存在
if (!fs.existsSync(targetPath)) {
console.error(`Target directory does not exist: ${targetPath}`);
process.exit(1);
}

// Copy files from dist to target
// 将文件从dist复制到目标
const copyFiles = (srcDir, destDir) => {
const entries = fs.readdirSync(srcDir, { withFileTypes: true });

Expand All @@ -37,14 +38,14 @@ const copyFiles = (srcDir, destDir) => {
const destPath = path.join(destDir, entry.name);

if (entry.isDirectory()) {
// Create directory if it doesn't exist
// 如果目录不存在,则创建该目录
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath);
}
// Recursively copy files
//递归复制文件
copyFiles(srcPath, destPath);
} else {
// Copy file and overwrite if exists
// 复制文件并覆盖(如果存在)
fs.copyFileSync(srcPath, destPath);
console.log(`Copied: ${srcPath} -> ${destPath}`);
}
Expand Down
4 changes: 3 additions & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "cross-env DEV_HTTP_PORT=3006 nodemon --config nodemon.json src/dev.js",
"build": "rimraf dist && cross-env NODE_ENV=production node esbuild.js && cross-env NODE_ENV=production node esbuild-config.js",
"build:copy": "rimraf dist && cross-env NODE_ENV=production node esbuild.js && cross-env NODE_ENV=production node esbuild-config.js && node copyDist.js \"D:\\\\soft\\\\猫影视\\\\Release\\\\data\\\\flutter_assets\\\\asset\\\\js\"",
"_增加字段_build:copy" "新添加用于支持DS源适配猫影视",
"build:config": "cross-env NODE_ENV=production node esbuild-config.js",
"build:rollup": "rimraf dist && cross-env NODE_ENV=production node rollup.js && cross-env NODE_ENV=production node rollup-config.js",
"build:rollup:config": "cross-env NODE_ENV=production node rollup-config.js"
Expand Down Expand Up @@ -38,6 +39,7 @@
"iconv-lite": "^0.6.3",
"node-json-db": "^2.3.0",
"node-rsa": "^1.1.1",
"qs": "^6.14.0"
"qs": "^6.14.0",
"_新增字段_qs" "新添加用于支持DS源适配猫影视"
}
}
14 changes: 7 additions & 7 deletions nodejs/src/dev.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { createServer } from 'http';
import os from 'os';
import { start } from './index.js';
import * as config from './index.config.js';
import os from 'os'; // 新添加用于支持DS源适配猫影视
import { start } from './index.js'; // 新添加用于支持DS源适配猫影视
import * as config from './index.config.js'; // 新添加用于支持DS源适配猫影视

globalThis.catServerFactory = (handle) => {
let port = 0;
const server = createServer((req, res) => {
handle(req, res);
});

//下面新添加用于支持DS源适配猫影视
server.on('listening', () => {
port = server.address().port;

// Get local IP addresses
// 获取本地IP地址
const networkInterfaces = os.networkInterfaces();
const addresses = [];
for (const interfaceName in networkInterfaces) {
Expand All @@ -30,9 +30,9 @@ globalThis.catServerFactory = (handle) => {
}
console.log(`- Node.js version: ${process.version}`);
});

//上面新添加用于支持DS源适配猫影视
server.on('close', () => {
console.log('Server closed on port ' + port);
console.log('Server closed on port ' + port); //上面新添加用于支持DS源适配猫影视
});

return server;
Expand Down
6 changes: 3 additions & 3 deletions nodejs/src/index.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
drpyS: {
config_url: 'http://127.0.0.1:5757/config/1?sub=all&pwd=',
},
drpyS: { //新添加用于支持DS源适配猫影视drpy-node
config_url: 'http://127.0.0.1:5757/config/1?sub=all&pwd=', // drpy-node 接口配置
}, // 新添加用于支持DS源适配猫影视
ffm3u8: {
url: 'https://cj.ffzyapi.com/api.php/provide/vod/',
categories: ['国产剧', '香港剧', '韩国剧', '欧美剧', '台湾剧', '日本剧', '海外剧', '泰国剧', '短剧', '动作片', '喜剧片', '爱情片', '科幻片', '恐怖片', '剧情片', '战争片', '动漫片', '大陆综艺', '港台综艺', '日韩综艺', '欧美综艺', '国产动漫', '日韩动漫', '欧美动漫', '港台动漫', '海外动漫', '记录片'],
Expand Down
16 changes: 8 additions & 8 deletions nodejs/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import alist from './spider/pan/alist.js';
import _13bqg from './spider/book/13bqg.js';
import copymanga from './spider/book/copymanga.js';
import ffm3u8 from './spider/video/ffm3u8.js';
import drpyS from './spider/video/drpyS.js';
import {request} from "./util/request.js";
import drpyS from './spider/video/drpyS.js'; // 新添加用于支持DS源适配猫影视
import {request} from "./util/request.js"; // 新添加用于支持DS源适配猫影视

const spiders = [ffm3u8, push, alist, _13bqg, copymanga, drpyS];
const spiders = [ffm3u8, push, alist, _13bqg, copymanga, drpyS]; // 新添加drpyS用于支持DS源适配猫影视
const spiderPrefix = '/spider';

/**
Expand All @@ -20,7 +20,7 @@ export default async function router(fastify) {
// register all spider router
spiders.forEach((spider) => {
const path = spiderPrefix + '/' + spider.meta.key + '/' + spider.meta.type;
fastify.register(spider.api, {prefix: path});
fastify.register(spider.api, {prefix: path}); // 新添加用于支持DS源适配猫影视
console.log('Register spider: ' + path);
});
// console.log(cfg.default);
Expand Down Expand Up @@ -51,7 +51,7 @@ export default async function router(fastify) {
* @param {import('fastify').FastifyReply} reply
*/
async function (_request, reply) {
reply.send({run: !fastify.stop});
reply.send({run: !fastify.stop}); // 新添加用于支持DS源适配猫影视
}
);
fastify.get(
Expand Down Expand Up @@ -84,7 +84,7 @@ export default async function router(fastify) {
let meta = Object.assign({}, spider.meta);
meta.api = spiderPrefix + '/' + meta.key + '/' + meta.type;
meta.key = 'nodejs_' + meta.key;
meta.ext = '';
meta.ext = ''; // 新添加用于支持DS源适配猫影视
const stype = spider.meta.type;
if (stype < 10) {
config.video.sites.push(meta);
Expand All @@ -98,7 +98,7 @@ export default async function router(fastify) {
config.pan.sites.push(meta);
}
});

// 下面代码 新添加用于支持DS源适配猫影视
console.log(cfg.default);
if (cfg.default.drpyS && cfg.default.drpyS.config_url) {
let drpyS_config_url = cfg.default.drpyS.config_url;
Expand All @@ -122,7 +122,7 @@ export default async function router(fastify) {
}
}
}

// 上面代码 新添加用于支持DS源适配猫影视
console.log(JSON.stringify(config));
reply.send(config);
}
Expand Down