diff --git a/.env.example b/.env.example deleted file mode 100644 index 966a036..0000000 --- a/.env.example +++ /dev/null @@ -1,8 +0,0 @@ -# jwt密钥 用于生成token加密 -JWT_SECRET="" - -# 用户注册码 -REGISTER_CODE='9527' - -# 服务端口 -PORT=8009 diff --git a/Dockerfile b/Dockerfile index 57bac04..137d3ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,9 @@ RUN apk add --no-cache nginx # 设置工作目录 WORKDIR /app +# 创建配置和数据目录 +RUN mkdir -p /app/config /app/data + # 复制前端构建产物到 Nginx COPY --from=frontend-build /app/dist /usr/share/nginx/html @@ -38,8 +41,15 @@ COPY --from=backend-build /app /app # 安装生产环境依赖 RUN npm install --production +# 设置数据卷 +VOLUME ["/app/config", "/app/data"] + # 暴露端口 EXPOSE 8008 -# 启动 Nginx 和后端服务 -CMD ["sh", "-c", "nginx -g 'daemon off;' & npm run start && wait"] +# 启动脚本 +COPY docker-entrypoint.sh /app/ +RUN chmod +x /app/docker-entrypoint.sh + +# 启动服务 +ENTRYPOINT ["/app/docker-entrypoint.sh"] diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 0000000..c9d6b4e --- /dev/null +++ b/backend/.env.example @@ -0,0 +1,9 @@ +# JWT配置 +JWT_SECRET=your_jwt_secret_here + +# Telegram配置 +TELEGRAM_BASE_URL=https://t.me/s + +# Telegram频道配置 +TELE_CHANNELS=[{"id":"guaguale115","name":"115网盘资源分享"},{"id":"hao115","name":"115网盘资源分享频道"},{"id":"yunpanshare","name":"网盘资源收藏(夸克)"}] + diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 9b03c69..094c569 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -11,86 +11,66 @@ interface Channel { interface CloudPatterns { baiduPan: RegExp; tianyi: RegExp; - weiyun: RegExp; aliyun: RegExp; pan115: RegExp; + pan123: RegExp; quark: RegExp; + yidong: RegExp; } -interface Cloud115Config { - userId: string; - cookie: string; -} -interface QuarkConfig { - userId: string; - cookie: string; -} -interface HttpProxyConfig { - host: string; - port: string; -} interface Config { jwtSecret: string; - registerCode: string; - rss: { + telegram: { baseUrl: string; channels: Channel[]; }; - telegram: { - baseUrl: string; - }; - httpProxy: HttpProxyConfig; cloudPatterns: CloudPatterns; - cloud115: Cloud115Config; - quark: QuarkConfig; } +// 从环境变量读取频道配置 +const getTeleChannels = (): Channel[] => { + try { + const channelsStr = process.env.TELE_CHANNELS; + if (channelsStr) { + return JSON.parse(channelsStr); + } + } catch (error) { + console.warn("无法解析 TELE_CHANNELS 环境变量,使用默认配置"); + } + + // 默认配置 + return [ + { + id: "guaguale115", + name: "115网盘资源分享", + }, + { + id: "hao115", + name: "115网盘资源分享频道", + }, + { + id: "yunpanshare", + name: "网盘资源收藏(夸克)", + }, + ]; +}; + export const config: Config = { jwtSecret: process.env.JWT_SECRET || "uV7Y$k92#LkF^q1b!", - rss: { - baseUrl: process.env.RSS_BASE_URL || "https://rsshub.rssforever.com/telegram/channel", - channels: [ - { - id: "guaguale115", - name: "115网盘资源分享", - }, - { - id: "hao115", - name: "115网盘资源分享频道", - }, - { - id: "yunpanshare", - name: "网盘资源收藏(夸克)", - }, - ], - }, - registerCode: process.env.REGISTER_CODE || "9527", telegram: { baseUrl: process.env.TELEGRAM_BASE_URL || "https://t.me/s", - }, - - httpProxy: { - host: process.env.HTTP_PROXY_HOST || "", - port: process.env.HTTP_PROXY_PORT || "", + channels: getTeleChannels(), }, cloudPatterns: { baiduPan: /https?:\/\/(?:pan|yun)\.baidu\.com\/[^\s<>"]+/g, tianyi: /https?:\/\/cloud\.189\.cn\/[^\s<>"]+/g, - weiyun: /https?:\/\/share\.weiyun\.com\/[^\s<>"]+/g, - aliyun: /https?:\/\/\w+\.aliyundrive\.com\/[^\s<>"]+/g, - // pan115有两个域名 115.com 和 anxia.com + aliyun: /https?:\/\/\w+\.(?:alipan|aliyundrive)\.com\/[^\s<>"]+/g, + // pan115有两个域名 115.com 和 anxia.com 和 115cdn.com pan115: /https?:\/\/(?:115|anxia|115cdn)\.com\/s\/[^\s<>"]+/g, + pan123: /https?:\/\/www\.123pan\.com\/s\/[^\s<>"]+/g, quark: /https?:\/\/pan\.quark\.cn\/[^\s<>"]+/g, - }, - - cloud115: { - userId: "", - cookie: process.env.CLOUD115_COOKIE || "", - }, - quark: { - userId: process.env.QUARK_USER_ID || "", - cookie: process.env.QUARK_COOKIE || "", + yidong: /https?:\/\/yun\.139\.com\/[^\s<>"]+/g, }, }; diff --git a/backend/src/services/Cloud115Service.ts b/backend/src/services/Cloud115Service.ts index 927a6c2..4b4543e 100644 --- a/backend/src/services/Cloud115Service.ts +++ b/backend/src/services/Cloud115Service.ts @@ -1,7 +1,6 @@ import { AxiosHeaders, AxiosInstance } from "axios"; // 导入 AxiosHeaders import { createAxiosInstance } from "../utils/axiosInstance"; import { Logger } from "../utils/logger"; -import { config } from "../config/index"; import { ShareInfoResponse } from "../types/cloud115"; interface Cloud115ListItem { @@ -128,7 +127,6 @@ export class Cloud115Service { }): Promise<{ message: string; data: unknown }> { const param = new URLSearchParams({ cid: params.cid, - user_id: config.cloud115.userId, share_code: params.shareCode, receive_code: params.receiveCode, file_id: params.fileId, diff --git a/backend/src/services/Searcher.ts b/backend/src/services/Searcher.ts index fd8bced..3dcca04 100644 --- a/backend/src/services/Searcher.ts +++ b/backend/src/services/Searcher.ts @@ -80,8 +80,8 @@ export class Searcher { const allResults: any[] = []; const channelList: any[] = channelId - ? config.rss.channels.filter((channel: any) => channel.id === channelId) - : config.rss.channels; + ? config.telegram.channels.filter((channel: any) => channel.id === channelId) + : config.telegram.channels; // 使用Promise.all进行并行请求 const searchPromises = channelList.map(async (channel) => { diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..988f1e0 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# 如果配置目录下没有 .env 文件,则复制示例文件 +if [ ! -f /app/config/.env ]; then + cp /app/.env.example /app/config/.env + echo "已创建默认配置文件 /app/config/.env,请根据需要修改配置" +fi + +# 创建配置文件软链接 +ln -sf /app/config/.env /app/.env + +# 启动 Nginx 和后端服务 +nginx -g 'daemon off;' & npm run start \ No newline at end of file