Skip to content

Commit a82a2a8

Browse files
committed
update:新增源
1 parent a0d9986 commit a82a2a8

18 files changed

+1078
-76
lines changed

Diff for: Dockerfile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 构建器阶段
2+
# 使用node:current-alpine3.21作为基础镜像
3+
FROM node:current-alpine3.21 AS builder
4+
5+
# 安装git
6+
RUN apk add --no-cache git
7+
8+
# 如果您需要配置git以使用特定的HTTP版本,请确保这是出于必要和安全考虑
9+
RUN git config --global http.version HTTP/1.1
10+
11+
# 创建一个工作目录
12+
WORKDIR /app
13+
14+
# 克隆GitHub仓库到工作目录
15+
RUN git clone https://github.com/hjdhnx/drpy-node.git .
16+
17+
# 设置npm镜像为npmmirror
18+
RUN npm config set registry https://registry.npmmirror.com
19+
20+
# 全局安装yarn和pm2工具
21+
RUN npm install -g yarn pm2
22+
23+
# 安装项目依赖项和puppeteer
24+
RUN yarn && yarn add puppeteer
25+
26+
# 复制工作目录中的所有文件到一个临时目录中
27+
# 以便在运行器阶段中使用
28+
RUN mkdir /tmp/drpys && cp -r /app/* /tmp/drpys/
29+
30+
# 运行器阶段
31+
# 使用alpine:latest作为基础镜像来创建一个更小的镜像
32+
# 但是无法用pm2
33+
FROM alpine:latest AS runner
34+
35+
# 创建一个工作目录
36+
WORKDIR /app
37+
38+
# 复制构建器阶段中准备好的文件和依赖项到运行器阶段的工作目录中
39+
COPY --from=builder /tmp/drpys /app
40+
41+
# 安装Node.js运行时(如果需要的话,这里已经假设在构建器阶段中安装了所有必要的Node.js依赖项)
42+
# 由于我们已经将node_modules目录复制到了运行器阶段,因此这里不需要再次安装npm或node_modules中的依赖项
43+
# 但是,我们仍然需要安装Node.js运行时本身(除非drpys项目是一个纯静态资源服务,不需要Node.js运行时)
44+
RUN apk add --no-cache nodejs
45+
46+
# 暴露应用程序端口(根据您的项目需求调整)
47+
EXPOSE 5757
48+
49+
# 指定容器启动时执行的命令
50+
CMD ["node", "index.js"]

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ nodejs作为服务端的drpy实现。全面升级异步写法
1313

1414
## 更新记录
1515

16-
### 20241217
16+
### 20241218
1717

18-
更新至V1.0.13
18+
更新至V1.0.14
1919

20-
1. 配置生成逻辑优化
20+
1. 增加源
21+
2. 优化vercel部署兼容性
2122

2223
[点此查看完整更新记录](docs/updateRecord.md)
2324

@@ -43,6 +44,7 @@ todo:
4344

4445
* [crypto-js-wasm使用教程](docs/crypto-js-wasm/readme-CN.md)
4546
* [puppeteer使用教程](docs/pupInstall.md)
47+
* [drpyS源属性说明](docs/ruleAttr.md)
4648

4749
## 问题说明
4850

Diff for: controllers/decoder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export default (fastify, options, done) => {
1919
.send({error: `Text content exceeds the maximum size of ${options.MAX_TEXT_SIZE / 1024} KB`});
2020
}
2121

22-
const authFilePath = path.join(options.rootDir, '.nomedia');
22+
const authFilePath = path.join(options.rootDir, 'nomedia.txt');
2323

2424
// 检查文件是否存在
2525
if (!existsSync(authFilePath)) {
26-
return reply.status(404).send({error: '.nomedia file not found'});
26+
return reply.status(404).send({error: 'nomedia.txt file not found'});
2727
}
2828
try {
2929
const local_auto_code = readFileSync(authFilePath, 'utf-8').trim();

Diff for: controllers/root.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import path from 'path';
2-
import {readdirSync, readFileSync, existsSync} from 'fs';
2+
import {readdirSync, readFileSync, writeFileSync, existsSync} from 'fs';
33
import '../utils/marked.min.js';
4+
import {computeHash} from '../utils/utils.js';
45

56
export default (fastify, options, done) => {
67
// 添加 / 接口
78
fastify.get('/', async (request, reply) => {
89
let readmePath = null;
10+
const indexHtmlPath = path.join(options.rootDir, 'public/index.html');
11+
// console.log(`indexHtmlPath:${indexHtmlPath}`);
912
const files = readdirSync(options.rootDir);
1013
// console.log(files);
1114
for (const file of files) {
@@ -16,20 +19,20 @@ export default (fastify, options, done) => {
1619
}
1720

1821
// 如果未找到 README.md 文件
19-
if (!readmePath) {
22+
if (!readmePath && !process.env.VERCEL) {
2023
let fileHtml = files.map(file => `<li>${file}</li>`).join('');
21-
reply.code(404).type('text/html;charset=utf-8').send(`<h1>README.md not found</h1><ul>${fileHtml}</ul>`);
22-
return;
24+
return reply.code(404).type('text/html;charset=utf-8').send(`<h1>README.md not found</h1><ul>${fileHtml}</ul>`);
25+
} else if (!readmePath && process.env.VERCEL) {
26+
const tmpIndexHtml = readFileSync(indexHtmlPath, 'utf-8');
27+
return reply.type('text/html;charset=utf-8').send(tmpIndexHtml);
2328
}
2429

2530
// 读取 README.md 文件内容
2631
const markdownContent = readFileSync(readmePath, 'utf-8');
2732

2833
// 将 Markdown 转换为 HTML
2934
const htmlContent = marked.parse(markdownContent);
30-
31-
// 返回 HTML 内容
32-
reply.type('text/html').send(`
35+
const indexHtml = `
3336
<!DOCTYPE html>
3437
<html lang="en">
3538
<head>
@@ -41,7 +44,22 @@ export default (fastify, options, done) => {
4144
${htmlContent}
4245
</body>
4346
</html>
44-
`);
47+
`;
48+
const indexHtmlHash = computeHash(indexHtml);
49+
if (!existsSync(indexHtmlPath)) {
50+
console.log(`将readme.md 本地文件:${indexHtmlPath}`);
51+
writeFileSync(indexHtmlPath, indexHtml, 'utf8');
52+
} else {
53+
const tmpIndexHtml = readFileSync(indexHtmlPath, 'utf-8');
54+
const tmpIndexHtmlHash = computeHash(tmpIndexHtml);
55+
if (indexHtmlHash !== tmpIndexHtmlHash) {
56+
console.log(`readme.md发生了改变,更新本地文件:${indexHtmlPath}`);
57+
writeFileSync(indexHtmlPath, indexHtml, 'utf8');
58+
}
59+
}
60+
61+
// 返回 HTML 内容
62+
reply.type('text/html;charset=utf-8').send(indexHtml);
4563
});
4664

4765
// 新增 /favicon.ico 路由

0 commit comments

Comments
 (0)