Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b645d3ae83 | ||
|
|
82048c3b73 | ||
|
|
1601364f3f | ||
|
|
2b1dbeaf42 | ||
|
|
4b5e50b0d9 | ||
|
|
e02422b774 | ||
|
|
676bf5cd40 | ||
|
|
16a2b586fd | ||
|
|
c1927a0ea9 | ||
|
|
cc7cdbb4a6 | ||
|
|
5f53d30be1 | ||
|
|
bf2d7c70c7 | ||
|
|
bc38acded3 | ||
|
|
f32b6cd5d0 | ||
|
|
28f894f988 | ||
|
|
ef0de7ad8c | ||
|
|
8fa1ed8fc2 | ||
|
|
dca0f1f0c1 | ||
|
|
8a5b084915 | ||
|
|
e6171fb34c | ||
|
|
5a625e5c0e | ||
|
|
37c25a9307 | ||
|
|
615149c83f | ||
|
|
a78ea7e5bd | ||
|
|
755a424530 | ||
|
|
c1948a888e | ||
|
|
7d8f4b32f7 | ||
|
|
0a9b053dff | ||
|
|
73440cca45 | ||
|
|
5987e1fb3e | ||
|
|
42722ca1d8 | ||
|
|
6efdea55aa | ||
|
|
f23e78e8dd | ||
|
|
26381fa6b0 | ||
|
|
eedd68d137 | ||
|
|
a04f16bfa4 | ||
|
|
93d6a1276a | ||
|
|
505b1d6c67 | ||
|
|
212ca3a879 | ||
|
|
65a35225d0 | ||
|
|
7ed0c04111 | ||
|
|
e8f70b286e | ||
|
|
e708524a41 | ||
|
|
a01dd06ef2 | ||
|
|
3c656eb880 | ||
|
|
89879e8c05 | ||
|
|
7c7ad6ba1f | ||
|
|
d0115c78f5 | ||
|
|
90e708c25f | ||
|
|
eb4aa1bb8d | ||
|
|
1f3a83b84d | ||
|
|
7bcec7e3b4 | ||
|
|
604ba2eec6 | ||
|
|
680108f499 | ||
|
|
301ed5648e | ||
|
|
b755b6b186 | ||
|
|
fa8da9ae25 | ||
|
|
03509eb723 | ||
|
|
4cd71a72e5 | ||
|
|
626313434a | ||
|
|
1a562a612c | ||
|
|
ddfb00298f | ||
|
|
cd7183f206 | ||
|
|
32bf77c3e0 | ||
|
|
9f6b811785 | ||
|
|
6c9034570c | ||
|
|
fe38437a7c | ||
|
|
06b01bf1f9 | ||
|
|
2fffdc30f5 | ||
|
|
5b701e499a | ||
|
|
25ecdb1078 | ||
|
|
1c884eb3b9 | ||
|
|
e4d2a1db52 | ||
|
|
4553b9a7a0 | ||
|
|
c290f5a6d9 | ||
|
|
8668bce863 | ||
|
|
390287876a | ||
|
|
f860cc1f57 | ||
|
|
f5106e782a | ||
|
|
c784b562c4 | ||
|
|
cd4fa8cc2b | ||
|
|
2041a7fa11 | ||
|
|
924903bd58 | ||
|
|
e3bf2d6d6b |
@@ -1,8 +0,0 @@
|
|||||||
# jwt密钥 用于生成token加密
|
|
||||||
JWT_SECRET=""
|
|
||||||
|
|
||||||
# 用户注册码
|
|
||||||
REGISTER_CODE='9527'
|
|
||||||
|
|
||||||
# 服务端口
|
|
||||||
PORT=8009
|
|
||||||
4
.eslintignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
coverage
|
||||||
57
.eslintrc.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
ignorePatterns: ["node_modules", "dist", "build", "coverage"],
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
es6: true,
|
||||||
|
},
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
plugins: ["@typescript-eslint"],
|
||||||
|
extends: [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:prettier/recommended",
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"@typescript-eslint/no-explicit-any": "warn",
|
||||||
|
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
|
||||||
|
"@typescript-eslint/explicit-function-return-type": 0,
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ["frontend/**/*.{js,ts,vue}"],
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
},
|
||||||
|
parser: "vue-eslint-parser",
|
||||||
|
parserOptions: {
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:vue/vue3-recommended",
|
||||||
|
"plugin:prettier/recommended",
|
||||||
|
],
|
||||||
|
plugins: ["@typescript-eslint", "vue"],
|
||||||
|
rules: {
|
||||||
|
"vue/multi-word-component-names": "off",
|
||||||
|
"vue/require-default-prop": "off",
|
||||||
|
"vue/no-v-html": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["backend/**/*.{js,ts}"],
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/explicit-function-return-type": 0,
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
50
.github/workflows/docker-build-test.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
name: Build and Push Multi-Arch Docker Image for Test
|
||||||
|
on:
|
||||||
|
workflow_dispatch: # 添加手动触发
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write # 必须授权以推送镜像
|
||||||
|
env:
|
||||||
|
REPO_NAME: ${{ github.repository }}
|
||||||
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
IMAGE_NAME: cloudsaver
|
||||||
|
steps:
|
||||||
|
- name: 检出代码
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: 设置小写镜像名称
|
||||||
|
run: |
|
||||||
|
LOWER_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
|
||||||
|
echo "LOWER_NAME=$LOWER_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: 登录到 GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: 登录到 Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: 设置 QEMU 支持多架构
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: 设置 Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: 构建并推送多架构 Docker 镜像
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64 # 指定架构:x86_64 和 ARM64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
ghcr.io/${{ env.LOWER_NAME }}:test
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:test
|
||||||
31
.github/workflows/docker-image.yml
vendored
@@ -1,24 +1,28 @@
|
|||||||
name: Docker Image CI/CD
|
name: Docker Image CI/CD
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
tags: ["v*.*.*"] # 支持标签触发(如 v1.0.0)
|
||||||
tags: [ "v*.*.*" ] # 支持标签触发(如 v1.0.0)
|
workflow_dispatch: # 添加手动触发
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write # 必须授权以推送镜像
|
packages: write # 必须授权以推送镜像
|
||||||
env:
|
env:
|
||||||
REPO_NAME: ${{ github.repository }}
|
REPO_NAME: ${{ github.repository }}
|
||||||
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
IMAGE_NAME: cloudsaver
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: 设置小写镜像名称
|
- name: 设置小写镜像名称和版本
|
||||||
run: |
|
run: |
|
||||||
LOWER_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
|
LOWER_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
|
||||||
echo "LOWER_NAME=$LOWER_NAME" >> $GITHUB_ENV
|
echo "LOWER_NAME=$LOWER_NAME" >> $GITHUB_ENV
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: 登录到 GitHub Container Registry
|
- name: 登录到 GitHub Container Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
@@ -27,11 +31,26 @@ jobs:
|
|||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: 登录到 Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: 设置 QEMU 支持多架构
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: 设置 Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: 构建并推送 Docker 镜像
|
- name: 构建并推送 Docker 镜像
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name == 'push' }} # 仅推送代码时上传镜像
|
platforms: linux/amd64,linux/arm64 # 指定架构:x86_64 和 ARM64
|
||||||
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/${{ env.LOWER_NAME }}:latest
|
ghcr.io/${{ env.LOWER_NAME }}:latest
|
||||||
ghcr.io/${{ env.LOWER_NAME }}:${{ github.sha }}
|
ghcr.io/${{ env.LOWER_NAME }}:${{ env.VERSION }}
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
|
||||||
|
|||||||
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
logs/
|
||||||
dist/
|
dist/
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
|
|||||||
@@ -25,3 +25,6 @@ node_modules
|
|||||||
# 系统文件
|
# 系统文件
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
# 版本控制
|
||||||
|
.git
|
||||||
14
.prettierrc.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
semi: true,
|
||||||
|
trailingComma: "es5",
|
||||||
|
singleQuote: false,
|
||||||
|
printWidth: 100,
|
||||||
|
tabWidth: 2,
|
||||||
|
useTabs: false,
|
||||||
|
endOfLine: "auto",
|
||||||
|
arrowParens: "always",
|
||||||
|
bracketSpacing: true,
|
||||||
|
embeddedLanguageFormatting: "auto",
|
||||||
|
htmlWhitespaceSensitivity: "css",
|
||||||
|
vueIndentScriptAndStyle: false,
|
||||||
|
};
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"semi": true,
|
|
||||||
"singleQuote": false,
|
|
||||||
"tabWidth": 2,
|
|
||||||
"printWidth": 100,
|
|
||||||
"trailingComma": "es5",
|
|
||||||
"bracketSpacing": true,
|
|
||||||
"endOfLine": "lf",
|
|
||||||
"arrowParens": "always",
|
|
||||||
"vueIndentScriptAndStyle": true
|
|
||||||
}
|
|
||||||
14
Dockerfile
@@ -26,6 +26,9 @@ RUN apk add --no-cache nginx
|
|||||||
# 设置工作目录
|
# 设置工作目录
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 创建配置和数据目录
|
||||||
|
RUN mkdir -p /app/config /app/data
|
||||||
|
|
||||||
# 复制前端构建产物到 Nginx
|
# 复制前端构建产物到 Nginx
|
||||||
COPY --from=frontend-build /app/dist /usr/share/nginx/html
|
COPY --from=frontend-build /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
@@ -38,8 +41,15 @@ COPY --from=backend-build /app /app
|
|||||||
# 安装生产环境依赖
|
# 安装生产环境依赖
|
||||||
RUN npm install --production
|
RUN npm install --production
|
||||||
|
|
||||||
|
# 设置数据卷
|
||||||
|
VOLUME ["/app/config", "/app/data"]
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 8008
|
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"]
|
||||||
|
|||||||
353
README.md
@@ -1,129 +1,296 @@
|
|||||||
# CloudSaver
|
# CloudSaver
|
||||||
|
|
||||||
一个基于 Vue 3 + Express 的网盘资源搜索与转存工具。
|

|
||||||
可通过docker 一键部署。
|

|
||||||
|

|
||||||
|
[](https://github.com/jiangrui1994/CloudSaver/stargazers)
|
||||||
|
|
||||||
## 特别声明
|
一个基于 Vue 3 + Express 的网盘资源搜索与转存工具,支持响应式布局,移动端与PC完美适配,可通过 Docker 一键部署。
|
||||||
|
|
||||||
1. 此项目仅供学习交流使用,请勿用于非法用途。
|
官方Telegram群组:[https://t.me/cloud_saver](https://t.me/cloud_saver)
|
||||||
2. 仅支持个人使用,不支持任何形式的 commercial 使用。
|
|
||||||
3. 禁止在项目页面上进行任何形式的广告宣传。
|
|
||||||
4. 所有搜索到的资源均来自第三方,本项目不对其真实性、合法性做出任何保证。
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. 此项目的资源搜索需要用到代理环境,请自行搭建。
|
|
||||||
2. 新用户注册,管理员默认注册码:230713;普通用户默认注册码:9527
|
|
||||||
|
|
||||||
## 功能特性
|
## 功能特性
|
||||||
|
|
||||||
- 支持多个资源订阅(电报群)源搜索
|
- 🔍 多源资源搜索
|
||||||
- 支持 115 网盘与夸克网盘**一键**资源转存
|
- 支持多个资源订阅源搜索
|
||||||
- 支持关键词搜索与资源链接解析
|
- 支持关键词搜索与资源链接解析
|
||||||
- 支持转存文件夹展示与选择
|
- 支持豆瓣热门榜单展示
|
||||||
- 支持多用户使用
|
- 💾 网盘资源转存
|
||||||
- 支持豆瓣热门榜单
|
- 支持 115 网盘与夸克网盘一键转存
|
||||||
- 支持热门榜单资源搜索
|
- 支持转存文件夹展示与选择
|
||||||
|
- 👥 多用户系统
|
||||||
|
- 支持用户注册登录
|
||||||
|
- 支持管理员与普通用户权限区分
|
||||||
|
- 📱 响应式设计
|
||||||
|
- 支持 PC 端与移动端自适应布局
|
||||||
|
- 针对不同设备优化的交互体验
|
||||||
|
|
||||||
## 预览
|
## 产品展示
|
||||||
|
|
||||||
### 登录/注册
|
### PC 端
|
||||||
|
|
||||||
<img src="./docs/images/login.png" width="400">
|
<div align="center">
|
||||||
<img src="./docs/images/register.png" width="400">
|
<img src="./docs/images/pc/login.png" width="400" alt="PC登录页面">
|
||||||
|
<img src="./docs/images/pc/douban.png" width="400" alt="PC豆瓣榜单">
|
||||||
|
<p>登录页面/榜单</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
### 最新资源搜索
|
<div align="center">
|
||||||
|
<img src="./docs/images/pc/search.png" width="400" alt="PC资源搜索">
|
||||||
|
<img src="./docs/images/pc/detail.png" width="400" alt="PC资源详情">
|
||||||
|
<p>资源搜索/资源详情</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<img src="./docs/images/search.png" width="400">
|
<div align="center">
|
||||||
|
<img src="./docs/images/pc/save.png" width="400" alt="PC资源转存">
|
||||||
### 关键词搜索
|
<img src="./docs/images/pc/save1.png" width="400" alt="PC资源转存">
|
||||||
|
<p>资源转存</p>
|
||||||
<img src="./docs/images/search-movie.png" width="400">
|
</div>
|
||||||
|
|
||||||
### 热门榜单
|
|
||||||
|
|
||||||
<img src="./docs/images/hotmovie.png" width="400">
|
|
||||||
|
|
||||||
|
|
||||||
### 转存
|
|
||||||
|
|
||||||
<img src="./docs/images/save.png" width="400">
|
|
||||||
|
|
||||||
|
|
||||||
### 系统设置
|
|
||||||
|
|
||||||
<img src="./docs/images/setting.png" width="400">
|
|
||||||
|
|
||||||
|
### 移动端
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<div style="display: inline-block; margin: 0 20px;">
|
||||||
|
<img src="./docs/images/mobile/login.png" width="200" alt="移动端登录页面">
|
||||||
|
<img src="./docs/images/mobile/search.png" width="200" alt="移动端资源搜索">
|
||||||
|
<img src="./docs/images/mobile/save.png" width="200" alt="移动端资源转存">
|
||||||
|
<img src="./docs/images/mobile/save1.png" width="200" alt="移动端资源转存">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
### 前端
|
### 前端
|
||||||
|
|
||||||
- Vue 3
|
- 核心框架
|
||||||
- TypeScript
|
- Vue 3
|
||||||
- Element Plus
|
- TypeScript
|
||||||
- Pinia
|
- Vite
|
||||||
- Vue Router
|
- 状态管理
|
||||||
- Vite
|
- Pinia
|
||||||
|
- 路由管理
|
||||||
|
- Vue Router
|
||||||
|
- UI 组件库
|
||||||
|
- Element Plus (PC)
|
||||||
|
- Vant (Mobile)
|
||||||
|
- 工具库
|
||||||
|
- Axios
|
||||||
|
|
||||||
### 后端
|
### 后端
|
||||||
|
|
||||||
- Node.js
|
- 运行环境
|
||||||
- Express
|
- Node.js
|
||||||
- TypeScript
|
- Express
|
||||||
- Sqlite3
|
- 数据存储
|
||||||
- RSS Parser
|
- SQLite3
|
||||||
|
|
||||||
## 环境配置
|
## 环境要求
|
||||||
|
|
||||||
### Node.js 版本
|
- Node.js >= 18.x
|
||||||
|
- pnpm >= 8.x (推荐)
|
||||||
|
|
||||||
本项目需要 `Node.js` 版本 `18.x` 或更高版本。请确保在运行项目之前安装了正确的版本。
|
## 快速开始
|
||||||
|
|
||||||
推荐使用pnpm进行依赖包安装,默认支持workspace,可以避免版本冲突。
|
### 开发环境
|
||||||
|
|
||||||
### 后端配置项
|
1. 克隆项目
|
||||||
|
|
||||||
复制环境变量模板文件:
|
|
||||||
|
|
||||||
```
|
|
||||||
cp .env.example ./backend/.env
|
|
||||||
```
|
|
||||||
|
|
||||||
- 根据 `.env.example`文件在 `backend`目录下创建 `.env`文件。
|
|
||||||
|
|
||||||
## 使用
|
|
||||||
|
|
||||||
### 开发环境本地运行
|
|
||||||
|
|
||||||
- 安装依赖:`npm run install`
|
|
||||||
- 启动开发环境:`npm run dev`
|
|
||||||
|
|
||||||
### 打包部署
|
|
||||||
|
|
||||||
- 前端打包:`npm run build:frontend` 或者进入前端目录`frontend`,执行 `npm run build`
|
|
||||||
- 将前端构建产物`dist`目录下的文件复制到服务器上,例如`nginx`的`html`目录下。
|
|
||||||
- 后端服务:先进入后端目录`backend`下`npm run build`构建,然后执行 `npm run start`启动,默认端口为`8009`。
|
|
||||||
- 通过`nginx`配置代理服务,将前端api的请求映射到后端服务。
|
|
||||||
|
|
||||||
## Docker 部署
|
|
||||||
|
|
||||||
- 构建镜像:
|
|
||||||
```bash
|
```bash
|
||||||
# 构建示例
|
git clone https://github.com/jiangrui1994/CloudSaver.git
|
||||||
docker build --platform linux/amd64 -t cloud-saver . --no-cache
|
cd CloudSaver
|
||||||
```
|
```
|
||||||
- 运行容器:
|
|
||||||
|
2. 安装依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -d -p 8008:8008 --name cloud-saver cloud-saver
|
pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
## 交流沟通
|
3. 配置环境变量
|
||||||
|
|
||||||
<img src="./docs/images/20250220115710.jpg" width="400">
|
```bash
|
||||||
<img src="./docs/images/20241217122628.jpg" width="400">
|
cp ./backend/.env.example ./backend/.env
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
根据 `.env.example` 文件说明配置必要的环境变量。
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
4. 启动开发服务器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### 生产环境部署
|
||||||
|
|
||||||
|
1. 构建前端
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build:frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 构建后端
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd backend
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 启动服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker 部署
|
||||||
|
|
||||||
|
说明:镜像源有**两个地址**供选择,下面部署命令中使用的是dockerhub托管的地址为例,github托管的地址请自行替换
|
||||||
|
|
||||||
|
- dockerhub托管:
|
||||||
|
- `jiangrui1994/cloudsaver:latest` 稳定版
|
||||||
|
- `jiangrui1994/cloudsaver:test` 测试版 (包含最新功能和bug修复,但可能不如稳定版稳定)
|
||||||
|
- github托管:
|
||||||
|
- `ghcr.io/jiangrui1994/cloudsaver:latest` 稳定版
|
||||||
|
- `ghcr.io/jiangrui1994/cloudsaver:test` 测试版 (包含最新功能和bug修复,但可能不如稳定版稳定)
|
||||||
|
|
||||||
|
#### 单容器部署
|
||||||
|
|
||||||
|
稳定版:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8008:8008 \
|
||||||
|
-v /your/local/path:/app/data \
|
||||||
|
-v /your/local/path/config:/app/config \
|
||||||
|
--name cloud-saver \
|
||||||
|
jiangrui1994/cloudsaver:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
测试版(包含最新功能和bug修复,但可能不如稳定版稳定):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8008:8008 \
|
||||||
|
-v /your/local/path:/app/data \
|
||||||
|
-v /your/local/path/config:/app/config \
|
||||||
|
--name cloud-saver \
|
||||||
|
jiangrui1994/cloudsaver:test
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Docker Compose 部署
|
||||||
|
|
||||||
|
创建 `docker-compose.yml` 文件:
|
||||||
|
|
||||||
|
稳定版:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
cloudsaver:
|
||||||
|
image: jiangrui1994/cloudsaver:latest
|
||||||
|
container_name: cloud-saver
|
||||||
|
ports:
|
||||||
|
- "8008:8008"
|
||||||
|
volumes:
|
||||||
|
- /your/local/path:/app/data
|
||||||
|
- /your/local/path/config:/app/config
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
测试版:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
cloudsaver:
|
||||||
|
image: jiangrui1994/cloudsaver:test
|
||||||
|
container_name: cloud-saver
|
||||||
|
ports:
|
||||||
|
- "8008:8008"
|
||||||
|
volumes:
|
||||||
|
- /your/local/path:/app/data
|
||||||
|
- /your/local/path/config:/app/config
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
#### /app/config 目录说明
|
||||||
|
|
||||||
|
- `env` 文件:包含后端环境变量配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# JWT配置
|
||||||
|
JWT_SECRET=your_jwt_secret_here
|
||||||
|
|
||||||
|
# Telegram配置
|
||||||
|
TELEGRAM_BASE_URL=https://t.me/s
|
||||||
|
|
||||||
|
# Telegram频道配置
|
||||||
|
TELE_CHANNELS=[{"id":"xxxx","name":"xxxx资源分享"}]
|
||||||
|
```
|
||||||
|
|
||||||
|
运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> **注意**: 测试版(:test标签)包含最新的功能开发和bug修复,但可能存在不稳定因素。建议生产环境使用稳定版(:latest标签)。
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. 资源搜索需要配置代理环境
|
||||||
|
2. 默认注册码
|
||||||
|
- 管理员:230713
|
||||||
|
- 普通用户:9527
|
||||||
|
|
||||||
|
## 联系方式
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<div>
|
||||||
|
<img src="./docs/images/wechat.jpg" height="200" alt="微信号">
|
||||||
|
<img src="./docs/images/wechat_2.jpg" height="200" alt="微信交流群">
|
||||||
|
<p>微信交流群</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## 支持项目
|
||||||
|
|
||||||
|
如果您觉得这个项目对您有帮助,可以考虑给予一点支持,这将帮助我们持续改进项目 ❤️
|
||||||
|
|
||||||
|
您可以:
|
||||||
|
|
||||||
|
- ⭐ 给项目点个 Star
|
||||||
|
- 🎉 分享给更多有需要的朋友
|
||||||
|
- ☕ 请作者喝杯咖啡
|
||||||
|
- 💰 **赞赏了一定记得和我联系**
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<div style="display: inline-block; margin: 0 20px;">
|
||||||
|
<img src="./docs/images/wechat_pay.jpg" height="300" alt="微信打赏">
|
||||||
|
<img src="./docs/images/alipay.png" height="300" alt="支付宝打赏">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## 特别声明
|
||||||
|
|
||||||
|
1. 本项目仅供学习交流使用,请勿用于非法用途
|
||||||
|
2. 仅支持个人使用,不支持任何形式的商业使用
|
||||||
|
3. 禁止在项目页面进行任何形式的广告宣传
|
||||||
|
4. 所有搜索到的资源均来自第三方,本项目不对其真实性、合法性做出任何保证
|
||||||
|
|
||||||
|
## 贡献指南
|
||||||
|
|
||||||
|
1. Fork 本仓库
|
||||||
|
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
||||||
|
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
||||||
|
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
||||||
|
5. 提交 Pull Request
|
||||||
|
|
||||||
|
## 开源协议
|
||||||
|
|
||||||
|
本项目基于 MIT 协议开源 - 查看 [LICENSE](LICENSE) 文件了解更多细节
|
||||||
|
|
||||||
|
## 鸣谢
|
||||||
|
|
||||||
|
- 👨💻 感谢所有为这个项目做出贡献的开发者们!
|
||||||
|
- 👥 感谢所有使用本项目并提供反馈的用户!
|
||||||
|
- 感谢所有给予支持和鼓励的朋友们!
|
||||||
|
|||||||
7
TODO.md
@@ -1,7 +0,0 @@
|
|||||||
# TODO
|
|
||||||
|
|
||||||
- ~~资源列表增加网盘标识~~
|
|
||||||
- ~~增加对夸克网盘转存的支持~~
|
|
||||||
- ~~增加搜索框直接解析链接~~
|
|
||||||
- ~~替换rsshub改为直接从telegram获取资源信息~~
|
|
||||||
- ~~增加资源列表web源加载更多功能~~
|
|
||||||
9
backend/.env.example
Normal file
@@ -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":"网盘资源收藏(夸克)"}]
|
||||||
|
|
||||||
@@ -15,12 +15,14 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.18.3",
|
"express": "^4.18.3",
|
||||||
|
"inversify": "^7.1.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"rss-parser": "^3.13.0",
|
"rss-parser": "^3.13.0",
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6",
|
||||||
|
"winston": "^3.17.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcrypt": "^5.0.2",
|
"@types/bcrypt": "^5.0.2",
|
||||||
|
|||||||
@@ -1,76 +1,57 @@
|
|||||||
// filepath: /d:/code/CloudDiskDown/backend/src/app.ts
|
// filepath: /d:/code/CloudDiskDown/backend/src/app.ts
|
||||||
import "./types/express";
|
import "./types/express";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import { container } from "./inversify.config";
|
||||||
import cookieParser from "cookie-parser";
|
import { TYPES } from "./core/types";
|
||||||
|
import { DatabaseService } from "./services/DatabaseService";
|
||||||
|
import { setupMiddlewares } from "./middleware";
|
||||||
import routes from "./routes/api";
|
import routes from "./routes/api";
|
||||||
|
import { logger } from "./utils/logger";
|
||||||
import { errorHandler } from "./middleware/errorHandler";
|
import { errorHandler } from "./middleware/errorHandler";
|
||||||
import sequelize from "./config/database";
|
class App {
|
||||||
import { authMiddleware } from "./middleware/auth";
|
private app = express();
|
||||||
import GlobalSetting from "./models/GlobalSetting";
|
private databaseService = container.get<DatabaseService>(TYPES.DatabaseService);
|
||||||
import Searcher from "./services/Searcher";
|
|
||||||
|
|
||||||
const app = express();
|
constructor() {
|
||||||
|
this.setupExpress();
|
||||||
app.use(
|
|
||||||
cors({
|
|
||||||
origin: "*",
|
|
||||||
credentials: true,
|
|
||||||
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
||||||
allowedHeaders: ["Content-Type", "Authorization", "Cookie"],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
app.use(cookieParser());
|
|
||||||
app.use(express.json());
|
|
||||||
|
|
||||||
// 应用 token 验证中间件,排除登录和注册接口
|
|
||||||
app.use((req, res, next) => {
|
|
||||||
if (
|
|
||||||
req.path === "/user/login" ||
|
|
||||||
req.path === "/user/register" ||
|
|
||||||
req.path.includes("tele-images")
|
|
||||||
) {
|
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
authMiddleware(req, res, next);
|
|
||||||
|
private setupExpress(): void {
|
||||||
|
// 设置中间件
|
||||||
|
setupMiddlewares(this.app);
|
||||||
|
|
||||||
|
// 设置路由
|
||||||
|
this.app.use("/", routes);
|
||||||
|
this.app.use(errorHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// 初始化数据库
|
||||||
|
await this.databaseService.initialize();
|
||||||
|
logger.info("数据库初始化成功");
|
||||||
|
|
||||||
|
// 启动服务器
|
||||||
|
const port = process.env.PORT || 8009;
|
||||||
|
this.app.listen(port, () => {
|
||||||
|
logger.info(`
|
||||||
|
🚀 服务器启动成功
|
||||||
|
🌍 监听端口: ${port}
|
||||||
|
🔧 运行环境: ${process.env.NODE_ENV || "development"}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("服务器启动失败:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建并启动应用
|
||||||
|
const application = new App();
|
||||||
|
application.start().catch((error) => {
|
||||||
|
logger.error("应用程序启动失败:", error);
|
||||||
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use("/", routes);
|
export default application;
|
||||||
|
|
||||||
const initializeGlobalSettings = async () => {
|
|
||||||
const settings = await GlobalSetting.findOne();
|
|
||||||
if (!settings) {
|
|
||||||
await GlobalSetting.create({
|
|
||||||
httpProxyHost: "127.0.0.1",
|
|
||||||
httpProxyPort: 7890,
|
|
||||||
isProxyEnabled: true,
|
|
||||||
CommonUserCode: 9527,
|
|
||||||
AdminUserCode: 230713,
|
|
||||||
});
|
|
||||||
console.log("Global settings initialized with default values.");
|
|
||||||
}
|
|
||||||
await Searcher.updateAxiosInstance();
|
|
||||||
};
|
|
||||||
|
|
||||||
// 错误处理
|
|
||||||
app.use(errorHandler);
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 8009;
|
|
||||||
|
|
||||||
// 在同步前禁用外键约束,同步后重新启用
|
|
||||||
sequelize
|
|
||||||
.query("PRAGMA foreign_keys = OFF") // 禁用外键
|
|
||||||
.then(() => sequelize.sync({ alter: true }))
|
|
||||||
.then(() => sequelize.query("PRAGMA foreign_keys = ON")) // 重新启用外键
|
|
||||||
.then(() => {
|
|
||||||
app.listen(PORT, async () => {
|
|
||||||
await initializeGlobalSettings();
|
|
||||||
console.log(`Server is running on port ${PORT}`);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Database sync failed:", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
export default app;
|
|
||||||
|
|||||||
@@ -11,86 +11,91 @@ interface Channel {
|
|||||||
interface CloudPatterns {
|
interface CloudPatterns {
|
||||||
baiduPan: RegExp;
|
baiduPan: RegExp;
|
||||||
tianyi: RegExp;
|
tianyi: RegExp;
|
||||||
weiyun: RegExp;
|
|
||||||
aliyun: RegExp;
|
aliyun: RegExp;
|
||||||
pan115: RegExp;
|
pan115: RegExp;
|
||||||
|
pan123: RegExp;
|
||||||
quark: 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 {
|
interface Config {
|
||||||
jwtSecret: string;
|
jwtSecret: string;
|
||||||
registerCode: string;
|
telegram: {
|
||||||
rss: {
|
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
channels: Channel[];
|
channels: Channel[];
|
||||||
};
|
};
|
||||||
telegram: {
|
|
||||||
baseUrl: string;
|
|
||||||
};
|
|
||||||
httpProxy: HttpProxyConfig;
|
|
||||||
cloudPatterns: CloudPatterns;
|
cloudPatterns: CloudPatterns;
|
||||||
cloud115: Cloud115Config;
|
app: {
|
||||||
quark: QuarkConfig;
|
port: number;
|
||||||
|
env: string;
|
||||||
|
};
|
||||||
|
database: {
|
||||||
|
type: string;
|
||||||
|
path: string;
|
||||||
|
};
|
||||||
|
jwt: {
|
||||||
|
secret: string;
|
||||||
|
expiresIn: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从环境变量读取频道配置
|
||||||
|
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 = {
|
export const config: Config = {
|
||||||
jwtSecret: process.env.JWT_SECRET || "uV7Y$k92#LkF^q1b!",
|
app: {
|
||||||
rss: {
|
port: parseInt(process.env.PORT || "8009"),
|
||||||
baseUrl: process.env.RSS_BASE_URL || "https://rsshub.rssforever.com/telegram/channel",
|
env: process.env.NODE_ENV || "development",
|
||||||
channels: [
|
|
||||||
{
|
|
||||||
id: "guaguale115",
|
|
||||||
name: "115网盘资源分享",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "hao115",
|
|
||||||
name: "115网盘资源分享频道",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "yunpanshare",
|
|
||||||
name: "网盘资源收藏(夸克)",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
registerCode: process.env.REGISTER_CODE || "9527",
|
database: {
|
||||||
|
type: "sqlite",
|
||||||
|
path: "./data/database.sqlite",
|
||||||
|
},
|
||||||
|
jwt: {
|
||||||
|
secret: process.env.JWT_SECRET || "your-secret-key",
|
||||||
|
expiresIn: "6h",
|
||||||
|
},
|
||||||
|
jwtSecret: process.env.JWT_SECRET || "uV7Y$k92#LkF^q1b!",
|
||||||
|
|
||||||
telegram: {
|
telegram: {
|
||||||
baseUrl: process.env.TELEGRAM_BASE_URL || "https://t.me/s",
|
baseUrl: process.env.TELEGRAM_BASE_URL || "https://t.me/s",
|
||||||
|
channels: getTeleChannels(),
|
||||||
},
|
},
|
||||||
|
|
||||||
httpProxy: {
|
|
||||||
host: process.env.HTTP_PROXY_HOST || "",
|
|
||||||
port: process.env.HTTP_PROXY_PORT || "",
|
|
||||||
},
|
|
||||||
|
|
||||||
cloudPatterns: {
|
cloudPatterns: {
|
||||||
baiduPan: /https?:\/\/(?:pan|yun)\.baidu\.com\/[^\s<>"]+/g,
|
baiduPan: /https?:\/\/(?:pan|yun)\.baidu\.com\/[^\s<>"]+/g,
|
||||||
tianyi: /https?:\/\/cloud\.189\.cn\/[^\s<>"]+/g,
|
tianyi: /https?:\/\/cloud\.189\.cn\/[^\s<>"]+/g,
|
||||||
weiyun: /https?:\/\/share\.weiyun\.com\/[^\s<>"]+/g,
|
aliyun: /https?:\/\/\w+\.(?:alipan|aliyundrive)\.com\/[^\s<>"]+/g,
|
||||||
aliyun: /https?:\/\/\w+\.aliyundrive\.com\/[^\s<>"]+/g,
|
// pan115有两个域名 115.com 和 anxia.com 和 115cdn.com
|
||||||
// pan115有两个域名 115.com 和 anxia.com
|
|
||||||
pan115: /https?:\/\/(?:115|anxia|115cdn)\.com\/s\/[^\s<>"]+/g,
|
pan115: /https?:\/\/(?:115|anxia|115cdn)\.com\/s\/[^\s<>"]+/g,
|
||||||
|
// 修改为匹配所有以123开头的域名
|
||||||
|
// eslint-disable-next-line no-useless-escape
|
||||||
|
pan123: /https?:\/\/(?:www\.)?123[^\/\s<>"]+\.com\/s\/[^\s<>"]+/g,
|
||||||
quark: /https?:\/\/pan\.quark\.cn\/[^\s<>"]+/g,
|
quark: /https?:\/\/pan\.quark\.cn\/[^\s<>"]+/g,
|
||||||
},
|
yidong: /https?:\/\/caiyun\.139\.com\/[^\s<>"]+/g,
|
||||||
|
|
||||||
cloud115: {
|
|
||||||
userId: "",
|
|
||||||
cookie: process.env.CLOUD115_COOKIE || "",
|
|
||||||
},
|
|
||||||
quark: {
|
|
||||||
userId: process.env.QUARK_USER_ID || "",
|
|
||||||
cookie: process.env.QUARK_COOKIE || "",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
32
backend/src/controllers/BaseCloudController.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { BaseController } from "./BaseController";
|
||||||
|
import { ICloudStorageService } from "@/types/services";
|
||||||
|
|
||||||
|
export abstract class BaseCloudController extends BaseController {
|
||||||
|
constructor(protected cloudService: ICloudStorageService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getShareInfo(req: Request, res: Response): Promise<void> {
|
||||||
|
await this.handleRequest(req, res, async () => {
|
||||||
|
const { shareCode, receiveCode } = req.query;
|
||||||
|
// await this.cloudService.setCookie(req);
|
||||||
|
return await this.cloudService.getShareInfo(shareCode as string, receiveCode as string);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFolderList(req: Request, res: Response): Promise<void> {
|
||||||
|
await this.handleRequest(req, res, async () => {
|
||||||
|
const { parentCid } = req.query;
|
||||||
|
await this.cloudService.setCookie(req);
|
||||||
|
return await this.cloudService.getFolderList(parentCid as string);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveFile(req: Request, res: Response): Promise<void> {
|
||||||
|
await this.handleRequest(req, res, async () => {
|
||||||
|
await this.cloudService.setCookie(req);
|
||||||
|
return await this.cloudService.saveSharedFile(req.body);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/src/controllers/BaseController.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { ApiResponse } from "../core/ApiResponse";
|
||||||
|
interface ApiResponseData<T> {
|
||||||
|
data?: T;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class BaseController {
|
||||||
|
protected async handleRequest<T>(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
action: () => Promise<ApiResponseData<T> | void>
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const result = await action();
|
||||||
|
if (result) {
|
||||||
|
res.json(ApiResponse.success(result.data, result.message));
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
||||||
|
res.status(200).json(ApiResponse.error(errorMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,61 +1,11 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
|
||||||
import { Cloud115Service } from "../services/Cloud115Service";
|
import { Cloud115Service } from "../services/Cloud115Service";
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
import { injectable, inject } from "inversify";
|
||||||
import UserSetting from "../models/UserSetting";
|
import { TYPES } from "../core/types";
|
||||||
|
import { BaseCloudController } from "./BaseCloudController";
|
||||||
|
|
||||||
const cloud115 = new Cloud115Service();
|
@injectable()
|
||||||
const setCookie = async (req: Request) => {
|
export class Cloud115Controller extends BaseCloudController {
|
||||||
const userId = req.user?.userId;
|
constructor(@inject(TYPES.Cloud115Service) cloud115Service: Cloud115Service) {
|
||||||
const userSetting = await UserSetting.findOne({
|
super(cloud115Service);
|
||||||
where: { userId },
|
|
||||||
});
|
|
||||||
console.log(userSetting?.dataValues.cloud115Cookie);
|
|
||||||
if (userSetting && userSetting.dataValues.cloud115Cookie) {
|
|
||||||
cloud115.setCookie(userSetting.dataValues.cloud115Cookie);
|
|
||||||
} else {
|
|
||||||
throw new Error("请先设置115网盘cookie");
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const cloud115Controller = {
|
|
||||||
async getShareInfo(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { shareCode, receiveCode } = req.query;
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await cloud115.getShareInfo(shareCode as string, receiveCode as string);
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
sendError(res, { message: (error as Error).message || "获取分享信息失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async getFolderList(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { parentCid } = req.query;
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await cloud115.getFolderList(parentCid as string);
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
sendError(res, { message: (error as Error).message || "获取目录列表失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async saveFile(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { shareCode, receiveCode, fileId, folderId } = req.body;
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await cloud115.saveSharedFile({
|
|
||||||
shareCode,
|
|
||||||
receiveCode,
|
|
||||||
fileId,
|
|
||||||
cid: folderId,
|
|
||||||
});
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
sendError(res, { message: (error as Error).message || "保存文件失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Cloud115ServiceInstance = cloud115;
|
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response } from "express";
|
||||||
import DoubanService from "../services/DoubanService";
|
import { injectable, inject } from "inversify";
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
import { TYPES } from "../core/types";
|
||||||
|
import { DoubanService } from "../services/DoubanService";
|
||||||
|
import { BaseController } from "./BaseController";
|
||||||
|
|
||||||
const doubanService = new DoubanService();
|
@injectable()
|
||||||
|
export class DoubanController extends BaseController {
|
||||||
|
constructor(@inject(TYPES.DoubanService) private doubanService: DoubanService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
export const doubanController = {
|
async getDoubanHotList(req: Request, res: Response): Promise<void> {
|
||||||
async getDoubanHotList(req: Request, res: Response, next: NextFunction) {
|
await this.handleRequest(req, res, async () => {
|
||||||
try {
|
|
||||||
const { type = "movie", tag = "热门", page_limit = "50", page_start = "0" } = req.query;
|
const { type = "movie", tag = "热门", page_limit = "50", page_start = "0" } = req.query;
|
||||||
const result = await doubanService.getHotList({
|
const result = await this.doubanService.getHotList({
|
||||||
type: type as string,
|
type: type as string,
|
||||||
tag: tag as string,
|
tag: tag as string,
|
||||||
page_limit: page_limit as string,
|
page_limit: page_limit as string,
|
||||||
page_start: page_start as string,
|
page_start: page_start as string,
|
||||||
});
|
});
|
||||||
sendSuccess(res, result);
|
return result;
|
||||||
} catch (error) {
|
});
|
||||||
sendError(res, { message: "获取热门列表失败" });
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,52 +1,12 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response } from "express";
|
||||||
|
import { injectable, inject } from "inversify";
|
||||||
|
import { TYPES } from "../core/types";
|
||||||
import { QuarkService } from "../services/QuarkService";
|
import { QuarkService } from "../services/QuarkService";
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
import { BaseCloudController } from "./BaseCloudController";
|
||||||
import UserSetting from "../models/UserSetting";
|
|
||||||
|
|
||||||
const quark = new QuarkService();
|
@injectable()
|
||||||
|
export class QuarkController extends BaseCloudController {
|
||||||
const setCookie = async (req: Request) => {
|
constructor(@inject(TYPES.QuarkService) quarkService: QuarkService) {
|
||||||
const userId = req.user?.userId;
|
super(quarkService);
|
||||||
const userSetting = await UserSetting.findOne({
|
|
||||||
where: { userId },
|
|
||||||
});
|
|
||||||
if (userSetting && userSetting.dataValues.quarkCookie) {
|
|
||||||
quark.setCookie(userSetting.dataValues.quarkCookie);
|
|
||||||
} else {
|
|
||||||
throw new Error("请先设置夸克网盘cookie");
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const quarkController = {
|
|
||||||
async getShareInfo(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { pwdId, passcode } = req.query;
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await quark.getShareInfo(pwdId as string, passcode as string);
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
sendError(res, { message: "获取分享信息失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async getFolderList(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { parentCid } = req.query;
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await quark.getFolderList(parentCid as string);
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
sendError(res, { message: (error as Error).message || "获取目录列表失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async saveFile(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
await setCookie(req);
|
|
||||||
const result = await quark.saveSharedFile(req.body);
|
|
||||||
sendSuccess(res, result);
|
|
||||||
} catch (error) {
|
|
||||||
sendError(res, { message: (error as Error).message || "保存文件失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,34 +1,23 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response } from "express";
|
||||||
import { RSSSearcher } from "../services/RSSSearcher";
|
import { injectable, inject } from "inversify";
|
||||||
import Searcher from "../services/Searcher";
|
import { TYPES } from "../core/types";
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
import { Searcher } from "../services/Searcher";
|
||||||
|
import { BaseController } from "./BaseController";
|
||||||
|
|
||||||
export const resourceController = {
|
@injectable()
|
||||||
async rssSearch(req: Request, res: Response, next: NextFunction) {
|
export class ResourceController extends BaseController {
|
||||||
try {
|
constructor(@inject(TYPES.Searcher) private searcher: Searcher) {
|
||||||
const { keyword } = req.query;
|
super();
|
||||||
const searcher = new RSSSearcher();
|
}
|
||||||
const result = await searcher.searchAll(keyword as string);
|
|
||||||
sendSuccess(res, result);
|
async search(req: Request, res: Response): Promise<void> {
|
||||||
} catch (error) {
|
await this.handleRequest(req, res, async () => {
|
||||||
sendError(res, {
|
const { keyword, channelId = "", lastMessageId = "" } = req.query;
|
||||||
message: (error as Error).message || "RSS 搜索失败",
|
return await this.searcher.searchAll(
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async search(req: Request, res: Response, next: NextFunction) {
|
|
||||||
try {
|
|
||||||
const { keyword, channelId = "", lastMessageId = "" } = req.query; // Remove `: string` from here
|
|
||||||
const result = await Searcher.searchAll(
|
|
||||||
keyword as string,
|
keyword as string,
|
||||||
channelId as string,
|
channelId as string,
|
||||||
lastMessageId as string
|
lastMessageId as string
|
||||||
);
|
);
|
||||||
sendSuccess(res, result);
|
});
|
||||||
} catch (error) {
|
}
|
||||||
sendError(res, {
|
}
|
||||||
message: (error as Error).message || "搜索资源失败",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,57 +1,28 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response } from "express";
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
import { injectable, inject } from "inversify";
|
||||||
import Searcher from "../services/Searcher";
|
import { TYPES } from "../core/types";
|
||||||
import UserSetting from "../models/UserSetting";
|
import { SettingService } from "../services/SettingService";
|
||||||
import GlobalSetting from "../models/GlobalSetting";
|
import { BaseController } from "./BaseController";
|
||||||
|
|
||||||
export const settingController = {
|
@injectable()
|
||||||
async get(req: Request, res: Response) {
|
export class SettingController extends BaseController {
|
||||||
try {
|
constructor(@inject(TYPES.SettingService) private settingService: SettingService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(req: Request, res: Response): Promise<void> {
|
||||||
|
await this.handleRequest(req, res, async () => {
|
||||||
const userId = req.user?.userId;
|
const userId = req.user?.userId;
|
||||||
const role = req.user?.role;
|
const role = Number(req.user?.role);
|
||||||
if (userId !== null) {
|
return await this.settingService.getSettings(userId, role);
|
||||||
let userSettings = await UserSetting.findOne({ where: { userId } });
|
});
|
||||||
if (!userSettings) {
|
}
|
||||||
userSettings = {
|
|
||||||
userId: userId,
|
async save(req: Request, res: Response): Promise<void> {
|
||||||
cloud115Cookie: "",
|
await this.handleRequest(req, res, async () => {
|
||||||
quarkCookie: "",
|
|
||||||
} as UserSetting;
|
|
||||||
if (userSettings) {
|
|
||||||
await UserSetting.create(userSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const globalSetting = await GlobalSetting.findOne();
|
|
||||||
sendSuccess(res, {
|
|
||||||
data: {
|
|
||||||
userSettings,
|
|
||||||
globalSetting: role === 1 ? globalSetting : null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sendError(res, { message: "用户ID无效" });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log("获取设置失败:" + error);
|
|
||||||
sendError(res, { message: (error as Error).message || "获取设置失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async save(req: Request, res: Response) {
|
|
||||||
try {
|
|
||||||
const userId = req.user?.userId;
|
const userId = req.user?.userId;
|
||||||
const role = req.user?.role;
|
const role = Number(req.user?.role);
|
||||||
if (userId !== null) {
|
return await this.settingService.saveSettings(userId, role, req.body);
|
||||||
const { userSettings, globalSetting } = req.body;
|
});
|
||||||
await UserSetting.update(userSettings, { where: { userId } });
|
}
|
||||||
if (role === 1 && globalSetting) await GlobalSetting.update(globalSetting, { where: {} });
|
}
|
||||||
Searcher.updateAxiosInstance();
|
|
||||||
sendSuccess(res, {
|
|
||||||
message: "保存成功",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log("保存设置失败:" + error);
|
|
||||||
sendError(res, { message: (error as Error).message || "保存设置失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
18
backend/src/controllers/sponsors.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { injectable, inject } from "inversify";
|
||||||
|
import { TYPES } from "../core/types";
|
||||||
|
import { SponsorsService } from "../services/SponsorsService";
|
||||||
|
import { BaseController } from "./BaseController";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class SponsorsController extends BaseController {
|
||||||
|
constructor(@inject(TYPES.SponsorsService) private sponsorsService: SponsorsService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(req: Request, res: Response): Promise<void> {
|
||||||
|
await this.handleRequest(req, res, async () => {
|
||||||
|
return await this.sponsorsService.getSponsors();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,57 +1,30 @@
|
|||||||
import axios, { AxiosInstance } from "axios";
|
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import tunnel from "tunnel";
|
import { injectable, inject } from "inversify";
|
||||||
import GlobalSetting from "../models/GlobalSetting";
|
import { TYPES } from "../core/types";
|
||||||
import { GlobalSettingAttributes } from "../models/GlobalSetting";
|
import { ImageService } from "../services/ImageService";
|
||||||
|
import { BaseController } from "./BaseController";
|
||||||
|
|
||||||
export class ImageControll {
|
@injectable()
|
||||||
private axiosInstance: AxiosInstance | null = null;
|
export class ImageController extends BaseController {
|
||||||
private isUpdate = false;
|
constructor(@inject(TYPES.ImageService) private imageService: ImageService) {
|
||||||
|
super();
|
||||||
constructor() {
|
|
||||||
this.initializeAxiosInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializeAxiosInstance(isUpdate = false) {
|
async getImages(req: Request, res: Response): Promise<void> {
|
||||||
let settings = null;
|
await this.handleRequest(req, res, async () => {
|
||||||
if (isUpdate) {
|
const url = decodeURIComponent((req.query.url as string) || "");
|
||||||
settings = await GlobalSetting.findOne();
|
const response = await this.imageService.getImages(url);
|
||||||
this.isUpdate = isUpdate;
|
|
||||||
} else {
|
// 设置正确的响应头
|
||||||
return;
|
res.setHeader("Content-Type", response.headers["content-type"]);
|
||||||
}
|
res.setHeader("Cache-Control", "no-cache");
|
||||||
const globalSetting = settings?.dataValues || ({} as GlobalSettingAttributes);
|
|
||||||
this.axiosInstance = axios.create({
|
// 确保清除任何可能导致304响应的头信息
|
||||||
timeout: 3000,
|
res.removeHeader("etag");
|
||||||
httpsAgent: tunnel.httpsOverHttp({
|
res.removeHeader("last-modified");
|
||||||
proxy: {
|
|
||||||
host: globalSetting.httpProxyHost,
|
// 直接传输图片数据
|
||||||
port: globalSetting.httpProxyPort,
|
response.data.pipe(res);
|
||||||
headers: {
|
|
||||||
"Proxy-Authorization": "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async getImages(req: Request, res: Response, url: string) {
|
|
||||||
try {
|
|
||||||
if (!this.isUpdate) await this.initializeAxiosInstance(true);
|
|
||||||
const response = await this.axiosInstance?.get(url, { responseType: "stream" });
|
|
||||||
res.set("Content-Type", response?.headers["content-type"]);
|
|
||||||
response?.data.pipe(res);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).send("Image fetch error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const iamgesInstance = new ImageControll();
|
|
||||||
|
|
||||||
export const imageControll = {
|
|
||||||
getImages: async (req: Request, res: Response) => {
|
|
||||||
const url = req.query.url as string;
|
|
||||||
iamgesInstance.getImages(req, res, url);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,62 +1,26 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import bcrypt from "bcrypt";
|
import { injectable, inject } from "inversify";
|
||||||
import jwt from "jsonwebtoken";
|
import { TYPES } from "../core/types";
|
||||||
import GlobalSetting from "../models/GlobalSetting";
|
import { UserService } from "../services/UserService";
|
||||||
import User from "../models/User";
|
import { BaseController } from "./BaseController";
|
||||||
import { config } from "../config";
|
|
||||||
import { sendSuccess, sendError } from "../utils/response";
|
|
||||||
|
|
||||||
const isValidInput = (input: string): boolean => {
|
@injectable()
|
||||||
// 检查是否包含空格或汉字
|
export class UserController extends BaseController {
|
||||||
const regex = /^[^\s\u4e00-\u9fa5]+$/;
|
constructor(@inject(TYPES.UserService) private userService: UserService) {
|
||||||
return regex.test(input);
|
super();
|
||||||
};
|
}
|
||||||
export const userController = {
|
|
||||||
async register(req: Request, res: Response) {
|
|
||||||
const { username, password, registerCode } = req.body;
|
|
||||||
const globalSetting = await GlobalSetting.findOne();
|
|
||||||
const registerCodeList = [
|
|
||||||
globalSetting?.dataValues.CommonUserCode,
|
|
||||||
globalSetting?.dataValues.AdminUserCode,
|
|
||||||
];
|
|
||||||
if (!registerCode || !registerCodeList.includes(Number(registerCode))) {
|
|
||||||
return sendError(res, { message: "注册码错误" });
|
|
||||||
}
|
|
||||||
// 验证输入
|
|
||||||
if (!isValidInput(username) || !isValidInput(password)) {
|
|
||||||
return sendError(res, { message: "用户名、密码或注册码不能包含空格或汉字" });
|
|
||||||
}
|
|
||||||
// 检查用户名是否已存在
|
|
||||||
const existingUser = await User.findOne({ where: { username } });
|
|
||||||
if (existingUser) {
|
|
||||||
return sendError(res, { message: "用户名已存在" });
|
|
||||||
}
|
|
||||||
const hashedPassword = await bcrypt.hash(password, 10);
|
|
||||||
try {
|
|
||||||
const role = registerCodeList.findIndex((x) => x === Number(registerCode));
|
|
||||||
const user = await User.create({ username, password: hashedPassword, role });
|
|
||||||
sendSuccess(res, {
|
|
||||||
data: user,
|
|
||||||
message: "用户注册成功",
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
sendError(res, { message: error.message || "用户注册失败" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async login(req: Request, res: Response) {
|
async register(req: Request, res: Response): Promise<void> {
|
||||||
const { username, password } = req.body;
|
await this.handleRequest(req, res, async () => {
|
||||||
const user = await User.findOne({ where: { username } });
|
const { username, password, registerCode } = req.body;
|
||||||
if (!user || !(await bcrypt.compare(password, user.password))) {
|
return await this.userService.register(username, password, registerCode);
|
||||||
return sendError(res, { message: "用户名或密码错误" });
|
|
||||||
}
|
|
||||||
const token = jwt.sign({ userId: user.userId, role: user.role }, config.jwtSecret, {
|
|
||||||
expiresIn: "6h",
|
|
||||||
});
|
});
|
||||||
sendSuccess(res, {
|
}
|
||||||
data: {
|
|
||||||
token,
|
async login(req: Request, res: Response): Promise<void> {
|
||||||
},
|
await this.handleRequest(req, res, async () => {
|
||||||
|
const { username, password } = req.body;
|
||||||
|
return await this.userService.login(username, password);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
21
backend/src/core/ApiResponse.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export class ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data?: T;
|
||||||
|
message?: string;
|
||||||
|
code: number;
|
||||||
|
|
||||||
|
private constructor(success: boolean, code: number, data?: T, message?: string) {
|
||||||
|
this.success = success;
|
||||||
|
this.code = code;
|
||||||
|
this.data = data;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
static success<T>(data?: T, message = "操作成功"): ApiResponse<T> {
|
||||||
|
return new ApiResponse(true, 0, data, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static error(message: string, code = 10000): ApiResponse<null> {
|
||||||
|
return new ApiResponse(false, code, null, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
backend/src/core/types.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export const TYPES = {
|
||||||
|
DatabaseService: Symbol.for("DatabaseService"),
|
||||||
|
Cloud115Service: Symbol.for("Cloud115Service"),
|
||||||
|
QuarkService: Symbol.for("QuarkService"),
|
||||||
|
Searcher: Symbol.for("Searcher"),
|
||||||
|
DoubanService: Symbol.for("DoubanService"),
|
||||||
|
ImageService: Symbol.for("ImageService"),
|
||||||
|
SettingService: Symbol.for("SettingService"),
|
||||||
|
UserService: Symbol.for("UserService"),
|
||||||
|
SponsorsService: Symbol.for("SponsorsService"),
|
||||||
|
|
||||||
|
Cloud115Controller: Symbol.for("Cloud115Controller"),
|
||||||
|
QuarkController: Symbol.for("QuarkController"),
|
||||||
|
ResourceController: Symbol.for("ResourceController"),
|
||||||
|
DoubanController: Symbol.for("DoubanController"),
|
||||||
|
ImageController: Symbol.for("ImageController"),
|
||||||
|
SettingController: Symbol.for("SettingController"),
|
||||||
|
UserController: Symbol.for("UserController"),
|
||||||
|
SponsorsController: Symbol.for("SponsorsController"),
|
||||||
|
};
|
||||||
45
backend/src/inversify.config.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Container } from "inversify";
|
||||||
|
import { TYPES } from "./core/types";
|
||||||
|
|
||||||
|
// Services
|
||||||
|
import { DatabaseService } from "./services/DatabaseService";
|
||||||
|
import { Cloud115Service } from "./services/Cloud115Service";
|
||||||
|
import { QuarkService } from "./services/QuarkService";
|
||||||
|
import { Searcher } from "./services/Searcher";
|
||||||
|
import { DoubanService } from "./services/DoubanService";
|
||||||
|
import { UserService } from "./services/UserService";
|
||||||
|
import { ImageService } from "./services/ImageService";
|
||||||
|
import { SettingService } from "./services/SettingService";
|
||||||
|
import { SponsorsService } from "./services/SponsorsService";
|
||||||
|
// Controllers
|
||||||
|
import { Cloud115Controller } from "./controllers/cloud115";
|
||||||
|
import { QuarkController } from "./controllers/quark";
|
||||||
|
import { ResourceController } from "./controllers/resource";
|
||||||
|
import { DoubanController } from "./controllers/douban";
|
||||||
|
import { ImageController } from "./controllers/teleImages";
|
||||||
|
import { SettingController } from "./controllers/setting";
|
||||||
|
import { UserController } from "./controllers/user";
|
||||||
|
import { SponsorsController } from "./controllers/sponsors";
|
||||||
|
const container = new Container();
|
||||||
|
|
||||||
|
// Services
|
||||||
|
container.bind<DatabaseService>(TYPES.DatabaseService).to(DatabaseService).inSingletonScope();
|
||||||
|
container.bind<Cloud115Service>(TYPES.Cloud115Service).to(Cloud115Service).inSingletonScope();
|
||||||
|
container.bind<QuarkService>(TYPES.QuarkService).to(QuarkService).inSingletonScope();
|
||||||
|
container.bind<Searcher>(TYPES.Searcher).to(Searcher).inSingletonScope();
|
||||||
|
container.bind<ImageService>(TYPES.ImageService).to(ImageService).inSingletonScope();
|
||||||
|
container.bind<SettingService>(TYPES.SettingService).to(SettingService).inSingletonScope();
|
||||||
|
container.bind<DoubanService>(TYPES.DoubanService).to(DoubanService).inSingletonScope();
|
||||||
|
container.bind<UserService>(TYPES.UserService).to(UserService).inSingletonScope();
|
||||||
|
container.bind<SponsorsService>(TYPES.SponsorsService).to(SponsorsService).inSingletonScope();
|
||||||
|
// Controllers
|
||||||
|
container.bind<Cloud115Controller>(TYPES.Cloud115Controller).to(Cloud115Controller);
|
||||||
|
container.bind<QuarkController>(TYPES.QuarkController).to(QuarkController);
|
||||||
|
container.bind<ResourceController>(TYPES.ResourceController).to(ResourceController);
|
||||||
|
container.bind<DoubanController>(TYPES.DoubanController).to(DoubanController);
|
||||||
|
container.bind<ImageController>(TYPES.ImageController).to(ImageController);
|
||||||
|
container.bind<SettingController>(TYPES.SettingController).to(SettingController);
|
||||||
|
container.bind<UserController>(TYPES.UserController).to(UserController);
|
||||||
|
container.bind<SponsorsController>(TYPES.SponsorsController).to(SponsorsController);
|
||||||
|
|
||||||
|
export { container };
|
||||||
@@ -15,8 +15,8 @@ export const authMiddleware = async (
|
|||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) => {
|
): Promise<void | Response> => {
|
||||||
if (req.path === "/user/login" || req.path === "/user/register") {
|
if (req.path === "/user/login" || req.path === "/user/register" || req.path === "/tele-images/") {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
backend/src/middleware/cors.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
|
export const cors = () => {
|
||||||
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||||
|
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Cookie");
|
||||||
|
res.header("Access-Control-Allow-Credentials", "true");
|
||||||
|
|
||||||
|
if (req.method === "OPTIONS") {
|
||||||
|
return res.sendStatus(200);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
export const errorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {
|
interface CustomError extends Error {
|
||||||
console.error(err);
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const errorHandler = (err: CustomError, req: Request, res: Response): void => {
|
||||||
res.status(err.status || 500).json({
|
res.status(err.status || 500).json({
|
||||||
success: false,
|
success: false,
|
||||||
error: err.message || "服务器内部错误",
|
error: err.message || "服务器内部错误",
|
||||||
|
|||||||
14
backend/src/middleware/index.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Application } from "express";
|
||||||
|
import express from "express";
|
||||||
|
import { authMiddleware } from "./auth";
|
||||||
|
import { requestLogger } from "./requestLogger";
|
||||||
|
import { rateLimiter } from "./rateLimiter";
|
||||||
|
import { cors } from "./cors";
|
||||||
|
|
||||||
|
export const setupMiddlewares = (app: Application) => {
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(cors());
|
||||||
|
app.use(requestLogger());
|
||||||
|
app.use(rateLimiter());
|
||||||
|
app.use(authMiddleware);
|
||||||
|
};
|
||||||
27
backend/src/middleware/rateLimiter.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
|
const requestCounts = new Map<string, { count: number; timestamp: number }>();
|
||||||
|
const WINDOW_MS = 60 * 1000; // 1分钟窗口
|
||||||
|
const MAX_REQUESTS = 600; // 每个IP每分钟最多60个请求
|
||||||
|
|
||||||
|
export const rateLimiter = () => {
|
||||||
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const ip = req.ip || req.socket.remoteAddress || "unknown";
|
||||||
|
const now = Date.now();
|
||||||
|
const record = requestCounts.get(ip) || { count: 0, timestamp: now };
|
||||||
|
|
||||||
|
if (now - record.timestamp > WINDOW_MS) {
|
||||||
|
record.count = 0;
|
||||||
|
record.timestamp = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
record.count++;
|
||||||
|
requestCounts.set(ip, record);
|
||||||
|
|
||||||
|
if (record.count > MAX_REQUESTS) {
|
||||||
|
return res.status(429).json({ message: "请求过于频繁,请稍后再试" });
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
23
backend/src/middleware/requestLogger.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
|
const excludePaths = ["/tele-images/"];
|
||||||
|
|
||||||
|
export const requestLogger = () => {
|
||||||
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const start = Date.now();
|
||||||
|
res.on("finish", () => {
|
||||||
|
if (excludePaths.includes(req.path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const duration = Date.now() - start;
|
||||||
|
logger.info({
|
||||||
|
method: req.method,
|
||||||
|
path: req.path,
|
||||||
|
status: res.statusCode,
|
||||||
|
duration: `${duration}ms`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
export const validateRequest = (requiredParams: string[]) => {
|
export const validateRequest = (
|
||||||
|
requiredParams: string[]
|
||||||
|
): ((req: Request, res: Response, next: NextFunction) => Response | void) => {
|
||||||
return (req: Request, res: Response, next: NextFunction) => {
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
const missingParams = requiredParams.filter((param) => !req.query[param] && !req.body[param]);
|
const missingParams = requiredParams.filter((param) => !req.query[param] && !req.body[param]);
|
||||||
if (missingParams.length > 0) {
|
if (missingParams.length > 0) {
|
||||||
|
|||||||
@@ -1,37 +1,55 @@
|
|||||||
import express from "express";
|
import { Router } from "express";
|
||||||
import { cloud115Controller } from "../controllers/cloud115";
|
import { container } from "../inversify.config";
|
||||||
import { quarkController } from "../controllers/quark";
|
import { TYPES } from "../core/types";
|
||||||
import { resourceController } from "../controllers/resource";
|
import { Cloud115Controller } from "../controllers/cloud115";
|
||||||
import { doubanController } from "../controllers/douban";
|
import { QuarkController } from "../controllers/quark";
|
||||||
import { imageControll } from "../controllers/teleImages";
|
import { ResourceController } from "../controllers/resource";
|
||||||
import settingRoutes from "./setting";
|
import { DoubanController } from "../controllers/douban";
|
||||||
import userRoutes from "./user";
|
import { ImageController } from "../controllers/teleImages";
|
||||||
|
import { SettingController } from "../controllers/setting";
|
||||||
|
import { UserController } from "../controllers/user";
|
||||||
|
import { SponsorsController } from "../controllers/sponsors";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = Router();
|
||||||
|
|
||||||
|
// 获取控制器实例
|
||||||
|
const cloud115Controller = container.get<Cloud115Controller>(TYPES.Cloud115Controller);
|
||||||
|
const quarkController = container.get<QuarkController>(TYPES.QuarkController);
|
||||||
|
const resourceController = container.get<ResourceController>(TYPES.ResourceController);
|
||||||
|
const doubanController = container.get<DoubanController>(TYPES.DoubanController);
|
||||||
|
const imageController = container.get<ImageController>(TYPES.ImageController);
|
||||||
|
const settingController = container.get<SettingController>(TYPES.SettingController);
|
||||||
|
const userController = container.get<UserController>(TYPES.UserController);
|
||||||
|
const sponsorsController = container.get<SponsorsController>(TYPES.SponsorsController);
|
||||||
|
|
||||||
// 用户相关路由
|
// 用户相关路由
|
||||||
router.use("/user", userRoutes);
|
router.post("/user/login", (req, res) => userController.login(req, res));
|
||||||
|
router.post("/user/register", (req, res) => userController.register(req, res));
|
||||||
|
|
||||||
router.use("/tele-images", imageControll.getImages);
|
// 图片相关路由
|
||||||
|
router.get("/tele-images", (req, res) => imageController.getImages(req, res));
|
||||||
|
|
||||||
// 设置相关路由
|
// 设置相关路由
|
||||||
router.use("/setting", settingRoutes);
|
router.get("/setting/get", (req, res) => settingController.get(req, res));
|
||||||
|
router.post("/setting/save", (req, res) => settingController.save(req, res));
|
||||||
|
|
||||||
// 资源搜索
|
// 资源搜索
|
||||||
router.get("/search", resourceController.search);
|
router.get("/search", (req, res) => resourceController.search(req, res));
|
||||||
router.get("/rssSearch", resourceController.rssSearch);
|
|
||||||
|
// 获取赞助者列表
|
||||||
|
router.get("/sponsors", (req, res) => sponsorsController.get(req, res));
|
||||||
|
|
||||||
// 115网盘相关
|
// 115网盘相关
|
||||||
router.get("/cloud115/share-info", cloud115Controller.getShareInfo);
|
router.get("/cloud115/share-info", (req, res) => cloud115Controller.getShareInfo(req, res));
|
||||||
router.get("/cloud115/folders", cloud115Controller.getFolderList);
|
router.get("/cloud115/folders", (req, res) => cloud115Controller.getFolderList(req, res));
|
||||||
router.post("/cloud115/save", cloud115Controller.saveFile);
|
router.post("/cloud115/save", (req, res) => cloud115Controller.saveFile(req, res));
|
||||||
|
|
||||||
// 夸克网盘相关
|
// 夸克网盘相关
|
||||||
router.get("/quark/share-info", quarkController.getShareInfo);
|
router.get("/quark/share-info", (req, res) => quarkController.getShareInfo(req, res));
|
||||||
router.get("/quark/folders", quarkController.getFolderList);
|
router.get("/quark/folders", (req, res) => quarkController.getFolderList(req, res));
|
||||||
router.post("/quark/save", quarkController.saveFile);
|
router.post("/quark/save", (req, res) => quarkController.saveFile(req, res));
|
||||||
|
|
||||||
// 获取豆瓣热门列表
|
// 获取豆瓣热门列表
|
||||||
router.get("/douban/hot", doubanController.getDoubanHotList);
|
router.get("/douban/hot", (req, res) => doubanController.getDoubanHotList(req, res));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
import { settingController } from "../controllers/setting";
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
router.get("/get", settingController.get);
|
|
||||||
router.post("/save", settingController.save);
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// backend/src/routes/user.ts
|
|
||||||
import express from "express";
|
|
||||||
import { userController } from "../controllers/user";
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
router.post("/register", userController.register);
|
|
||||||
router.post("/login", userController.login);
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@@ -1,14 +1,30 @@
|
|||||||
import { AxiosHeaders, AxiosInstance } from "axios"; // 导入 AxiosHeaders
|
import { AxiosHeaders, AxiosInstance } from "axios"; // 导入 AxiosHeaders
|
||||||
import { createAxiosInstance } from "../utils/axiosInstance";
|
import { createAxiosInstance } from "../utils/axiosInstance";
|
||||||
import { Logger } from "../utils/logger";
|
import { ShareInfoResponse, FolderListResponse, SaveFileParams } from "../types/cloud";
|
||||||
import { config } from "../config/index";
|
import { injectable } from "inversify";
|
||||||
import { ShareInfoResponse } from "../types/cloud115";
|
import { Request } from "express";
|
||||||
|
import UserSetting from "../models/UserSetting";
|
||||||
|
import { ICloudStorageService } from "@/types/services";
|
||||||
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
export class Cloud115Service {
|
interface Cloud115ListItem {
|
||||||
|
cid: string;
|
||||||
|
n: string;
|
||||||
|
s: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Cloud115FolderItem {
|
||||||
|
cid: string;
|
||||||
|
n: string;
|
||||||
|
ns: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class Cloud115Service implements ICloudStorageService {
|
||||||
private api: AxiosInstance;
|
private api: AxiosInstance;
|
||||||
private cookie: string = "";
|
private cookie: string = "";
|
||||||
|
|
||||||
constructor(cookie?: string) {
|
constructor() {
|
||||||
this.api = createAxiosInstance(
|
this.api = createAxiosInstance(
|
||||||
"https://webapi.115.com",
|
"https://webapi.115.com",
|
||||||
AxiosHeaders.from({
|
AxiosHeaders.from({
|
||||||
@@ -28,19 +44,23 @@ export class Cloud115Service {
|
|||||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
"Accept-Language": "zh-CN,zh;q=0.9",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
if (cookie) {
|
|
||||||
this.setCookie(cookie);
|
|
||||||
} else {
|
|
||||||
console.log("请注意:115网盘需要提供cookie进行身份验证");
|
|
||||||
}
|
|
||||||
this.api.interceptors.request.use((config) => {
|
this.api.interceptors.request.use((config) => {
|
||||||
config.headers.cookie = cookie || this.cookie;
|
config.headers.cookie = this.cookie;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCookie(cookie: string) {
|
async setCookie(req: Request): Promise<void> {
|
||||||
this.cookie = cookie;
|
const userId = req.user?.userId;
|
||||||
|
const userSetting = await UserSetting.findOne({
|
||||||
|
where: { userId },
|
||||||
|
});
|
||||||
|
if (userSetting && userSetting.dataValues.cloud115Cookie) {
|
||||||
|
this.cookie = userSetting.dataValues.cloud115Cookie;
|
||||||
|
} else {
|
||||||
|
throw new Error("请先设置115网盘cookie");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShareInfo(shareCode: string, receiveCode = ""): Promise<ShareInfoResponse> {
|
async getShareInfo(shareCode: string, receiveCode = ""): Promise<ShareInfoResponse> {
|
||||||
@@ -53,26 +73,29 @@ export class Cloud115Service {
|
|||||||
cid: "",
|
cid: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.data?.state && response.data.data?.list?.length > 0) {
|
if (response.data?.state && response.data.data?.list?.length > 0) {
|
||||||
return {
|
return {
|
||||||
data: response.data.data.list.map((item: any) => ({
|
data: {
|
||||||
fileId: item.cid,
|
list: response.data.data.list.map((item: Cloud115ListItem) => ({
|
||||||
fileName: item.n,
|
fileId: item.cid,
|
||||||
fileSize: item.s,
|
fileName: item.n,
|
||||||
})),
|
fileSize: item.s,
|
||||||
|
})),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
logger.error("未找到文件信息:", response.data);
|
||||||
|
throw new Error("未找到文件信息");
|
||||||
}
|
}
|
||||||
throw new Error("未找到文件信息");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFolderList(parentCid = "0") {
|
async getFolderList(parentCid = "0"): Promise<FolderListResponse> {
|
||||||
const response = await this.api.get("/files", {
|
const response = await this.api.get("/files", {
|
||||||
params: {
|
params: {
|
||||||
aid: 1,
|
aid: 1,
|
||||||
cid: parentCid,
|
cid: parentCid,
|
||||||
o: "user_ptime",
|
o: "user_ptime",
|
||||||
asc: 0,
|
asc: 1,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
show_dir: 1,
|
show_dir: 1,
|
||||||
limit: 50,
|
limit: 50,
|
||||||
@@ -80,48 +103,44 @@ export class Cloud115Service {
|
|||||||
format: "json",
|
format: "json",
|
||||||
star: 0,
|
star: 0,
|
||||||
suffix: "",
|
suffix: "",
|
||||||
natsort: 1,
|
natsort: 0,
|
||||||
|
snap: 0,
|
||||||
|
record_open_time: 1,
|
||||||
|
fc_mix: 0,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.data?.state) {
|
if (response.data?.state) {
|
||||||
return {
|
return {
|
||||||
data: response.data.data
|
data: response.data.data
|
||||||
.filter((item: any) => item.cid && !!item.ns)
|
.filter((item: Cloud115FolderItem) => item.cid && !!item.ns)
|
||||||
.map((folder: any) => ({
|
.map((folder: Cloud115FolderItem) => ({
|
||||||
cid: folder.cid,
|
cid: folder.cid,
|
||||||
name: folder.n,
|
name: folder.n,
|
||||||
path: response.data.path,
|
path: response.data.path,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
Logger.error("获取目录列表失败:", response.data.error);
|
logger.error("获取目录列表失败:", response.data.error);
|
||||||
throw new Error("获取115pan目录列表失败:" + response.data.error);
|
throw new Error("获取115pan目录列表失败:" + response.data.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSharedFile(params: {
|
async saveSharedFile(params: SaveFileParams): Promise<{ message: string; data: unknown }> {
|
||||||
cid: string;
|
|
||||||
shareCode: string;
|
|
||||||
receiveCode: string;
|
|
||||||
fileId: string;
|
|
||||||
}) {
|
|
||||||
const param = new URLSearchParams({
|
const param = new URLSearchParams({
|
||||||
cid: params.cid,
|
cid: params.folderId || "",
|
||||||
user_id: config.cloud115.userId,
|
share_code: params.shareCode || "",
|
||||||
share_code: params.shareCode,
|
receive_code: params.receiveCode || "",
|
||||||
receive_code: params.receiveCode,
|
file_id: params.fids?.[0] || "",
|
||||||
file_id: params.fileId,
|
|
||||||
});
|
});
|
||||||
const response = await this.api.post("/share/receive", param.toString());
|
const response = await this.api.post("/share/receive", param.toString());
|
||||||
Logger.info("保存文件:", response.data);
|
logger.info("保存文件:", response.data);
|
||||||
if (response.data.state) {
|
if (response.data.state) {
|
||||||
return {
|
return {
|
||||||
message: response.data.error,
|
message: response.data.error,
|
||||||
data: response.data.data,
|
data: response.data.data,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
Logger.error("保存文件失败:", response.data.error);
|
logger.error("保存文件失败:", response.data.error);
|
||||||
throw new Error("保存115pan文件失败:" + response.data.error);
|
throw new Error("保存115pan文件失败:" + response.data.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
backend/src/services/DatabaseService.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { Sequelize, QueryTypes } from "sequelize";
|
||||||
|
import GlobalSetting from "../models/GlobalSetting";
|
||||||
|
import { Searcher } from "./Searcher";
|
||||||
|
import sequelize from "../config/database";
|
||||||
|
|
||||||
|
// 全局设置默认值
|
||||||
|
const DEFAULT_GLOBAL_SETTINGS = {
|
||||||
|
httpProxyHost: "127.0.0.1",
|
||||||
|
httpProxyPort: 7890,
|
||||||
|
isProxyEnabled: false,
|
||||||
|
CommonUserCode: 9527,
|
||||||
|
AdminUserCode: 230713,
|
||||||
|
};
|
||||||
|
|
||||||
|
export class DatabaseService {
|
||||||
|
private sequelize: Sequelize;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.sequelize = sequelize;
|
||||||
|
}
|
||||||
|
|
||||||
|
async initialize(): Promise<void> {
|
||||||
|
try {
|
||||||
|
await this.sequelize.query("PRAGMA foreign_keys = OFF");
|
||||||
|
await this.cleanupBackupTables();
|
||||||
|
await this.sequelize.sync({ alter: true });
|
||||||
|
await this.sequelize.query("PRAGMA foreign_keys = ON");
|
||||||
|
await this.initializeGlobalSettings();
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`数据库初始化失败: ${(error as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async initializeGlobalSettings(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const settings = await GlobalSetting.findOne();
|
||||||
|
if (!settings) {
|
||||||
|
await GlobalSetting.create(DEFAULT_GLOBAL_SETTINGS);
|
||||||
|
console.log("✅ Global settings initialized with default values.");
|
||||||
|
}
|
||||||
|
await Searcher.updateAxiosInstance();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Failed to initialize global settings:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async cleanupBackupTables(): Promise<void> {
|
||||||
|
const backupTables = await this.sequelize.query<{ name: string }>(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%\\_backup%' ESCAPE '\\'",
|
||||||
|
{ type: QueryTypes.SELECT }
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const table of backupTables) {
|
||||||
|
if (table?.name) {
|
||||||
|
await this.sequelize.query(`DROP TABLE IF EXISTS ${table.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... 其他数据库相关方法
|
||||||
|
}
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
import { AxiosHeaders, AxiosInstance } from "axios";
|
import { AxiosHeaders, AxiosInstance } from "axios";
|
||||||
import { createAxiosInstance } from "../utils/axiosInstance";
|
import { createAxiosInstance } from "../utils/axiosInstance";
|
||||||
|
|
||||||
class DoubanService {
|
interface DoubanSubject {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
rate: string;
|
||||||
|
cover: string;
|
||||||
|
url: string;
|
||||||
|
is_new: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DoubanService {
|
||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
private api: AxiosInstance;
|
private api: AxiosInstance;
|
||||||
|
|
||||||
@@ -28,7 +37,12 @@ class DoubanService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHotList(params: { type: string; tag: string; page_limit: string; page_start: string }) {
|
async getHotList(params: {
|
||||||
|
type: string;
|
||||||
|
tag: string;
|
||||||
|
page_limit: string;
|
||||||
|
page_start: string;
|
||||||
|
}): Promise<{ data: DoubanSubject[] }> {
|
||||||
try {
|
try {
|
||||||
const response = await this.api.get("/search_subjects", {
|
const response = await this.api.get("/search_subjects", {
|
||||||
params: params,
|
params: params,
|
||||||
@@ -48,5 +62,3 @@ class DoubanService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DoubanService;
|
|
||||||
|
|||||||
68
backend/src/services/ImageService.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { injectable } from "inversify";
|
||||||
|
import axios, { AxiosInstance } from "axios";
|
||||||
|
import tunnel from "tunnel";
|
||||||
|
import GlobalSetting from "../models/GlobalSetting";
|
||||||
|
import { GlobalSettingAttributes } from "../models/GlobalSetting";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ImageService {
|
||||||
|
private axiosInstance: AxiosInstance | null = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
// 移除构造函数中的初始化,改为懒加载
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ensureAxiosInstance(): Promise<AxiosInstance> {
|
||||||
|
if (!this.axiosInstance) {
|
||||||
|
const settings = await GlobalSetting.findOne();
|
||||||
|
const globalSetting = settings?.dataValues || ({} as GlobalSettingAttributes);
|
||||||
|
|
||||||
|
this.axiosInstance = axios.create({
|
||||||
|
timeout: 30000,
|
||||||
|
headers: {
|
||||||
|
Accept: "image/*, */*",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
||||||
|
},
|
||||||
|
withCredentials: false,
|
||||||
|
maxRedirects: 5,
|
||||||
|
httpsAgent: globalSetting.isProxyEnabled
|
||||||
|
? tunnel.httpsOverHttp({
|
||||||
|
proxy: {
|
||||||
|
host: globalSetting.httpProxyHost,
|
||||||
|
port: globalSetting.httpProxyPort,
|
||||||
|
headers: {
|
||||||
|
"Proxy-Authorization": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.axiosInstance.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
(error) => {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.axiosInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAxiosInstance(): Promise<void> {
|
||||||
|
this.axiosInstance = null;
|
||||||
|
await this.ensureAxiosInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getImages(url: string): Promise<any> {
|
||||||
|
const axiosInstance = await this.ensureAxiosInstance();
|
||||||
|
|
||||||
|
return await axiosInstance.get(url, {
|
||||||
|
responseType: "stream",
|
||||||
|
validateStatus: (status) => status >= 200 && status < 300,
|
||||||
|
headers: {
|
||||||
|
Referer: new URL(url).origin,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,35 @@
|
|||||||
import { AxiosInstance, AxiosHeaders } from "axios";
|
import { AxiosInstance, AxiosHeaders } from "axios";
|
||||||
import { Logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
import { createAxiosInstance } from "../utils/axiosInstance";
|
import { createAxiosInstance } from "../utils/axiosInstance";
|
||||||
|
import { injectable } from "inversify";
|
||||||
|
import { Request } from "express";
|
||||||
|
import UserSetting from "../models/UserSetting";
|
||||||
|
import {
|
||||||
|
ShareInfoResponse,
|
||||||
|
FolderListResponse,
|
||||||
|
QuarkFolderItem,
|
||||||
|
SaveFileParams,
|
||||||
|
} from "../types/cloud";
|
||||||
|
import { ICloudStorageService } from "@/types/services";
|
||||||
|
|
||||||
export class QuarkService {
|
interface QuarkShareInfo {
|
||||||
|
stoken?: string;
|
||||||
|
pwdId?: string;
|
||||||
|
fileSize?: number;
|
||||||
|
list: {
|
||||||
|
fid: string;
|
||||||
|
file_name: string;
|
||||||
|
file_type: number;
|
||||||
|
share_fid_token: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class QuarkService implements ICloudStorageService {
|
||||||
private api: AxiosInstance;
|
private api: AxiosInstance;
|
||||||
private cookie: string = "";
|
private cookie: string = "";
|
||||||
|
|
||||||
constructor(cookie?: string) {
|
constructor() {
|
||||||
this.api = createAxiosInstance(
|
this.api = createAxiosInstance(
|
||||||
"https://drive-h.quark.cn",
|
"https://drive-h.quark.cn",
|
||||||
AxiosHeaders.from({
|
AxiosHeaders.from({
|
||||||
@@ -23,22 +46,26 @@ export class QuarkService {
|
|||||||
"sec-fetch-site": "same-site",
|
"sec-fetch-site": "same-site",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
if (cookie) {
|
|
||||||
this.setCookie(cookie);
|
|
||||||
} else {
|
|
||||||
console.log("请注意:夸克网盘需要提供cookie进行身份验证");
|
|
||||||
}
|
|
||||||
this.api.interceptors.request.use((config) => {
|
this.api.interceptors.request.use((config) => {
|
||||||
config.headers.cookie = cookie || this.cookie;
|
config.headers.cookie = this.cookie;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCookie(cookie: string) {
|
async setCookie(req: Request): Promise<void> {
|
||||||
this.cookie = cookie;
|
const userId = req.user?.userId;
|
||||||
|
const userSetting = await UserSetting.findOne({
|
||||||
|
where: { userId },
|
||||||
|
});
|
||||||
|
if (userSetting && userSetting.dataValues.quarkCookie) {
|
||||||
|
this.cookie = userSetting.dataValues.quarkCookie;
|
||||||
|
} else {
|
||||||
|
throw new Error("请先设置夸克网盘cookie");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShareInfo(pwdId: string, passcode = "") {
|
async getShareInfo(pwdId: string, passcode = ""): Promise<ShareInfoResponse> {
|
||||||
const response = await this.api.post(
|
const response = await this.api.post(
|
||||||
`/1/clouddrive/share/sharepage/token?pr=ucpro&fr=pc&uc_param_str=&__dt=994&__t=${Date.now()}`,
|
`/1/clouddrive/share/sharepage/token?pr=ucpro&fr=pc&uc_param_str=&__dt=994&__t=${Date.now()}`,
|
||||||
{
|
{
|
||||||
@@ -49,7 +76,7 @@ export class QuarkService {
|
|||||||
if (response.data?.status === 200 && response.data.data) {
|
if (response.data?.status === 200 && response.data.data) {
|
||||||
const fileInfo = response.data.data;
|
const fileInfo = response.data.data;
|
||||||
if (fileInfo.stoken) {
|
if (fileInfo.stoken) {
|
||||||
let res = await this.getShareList(pwdId, fileInfo.stoken);
|
const res = await this.getShareList(pwdId, fileInfo.stoken);
|
||||||
return {
|
return {
|
||||||
data: res,
|
data: res,
|
||||||
};
|
};
|
||||||
@@ -58,7 +85,7 @@ export class QuarkService {
|
|||||||
throw new Error("获取夸克分享信息失败");
|
throw new Error("获取夸克分享信息失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShareList(pwdId: string, stoken: string) {
|
async getShareList(pwdId: string, stoken: string): Promise<ShareInfoResponse["data"]> {
|
||||||
const response = await this.api.get("/1/clouddrive/share/sharepage/detail", {
|
const response = await this.api.get("/1/clouddrive/share/sharepage/detail", {
|
||||||
params: {
|
params: {
|
||||||
pr: "ucpro",
|
pr: "ucpro",
|
||||||
@@ -80,8 +107,8 @@ export class QuarkService {
|
|||||||
});
|
});
|
||||||
if (response.data?.data) {
|
if (response.data?.data) {
|
||||||
const list = response.data.data.list
|
const list = response.data.data.list
|
||||||
.filter((item: any) => item.fid)
|
.filter((item: QuarkShareInfo["list"][0]) => item.fid)
|
||||||
.map((folder: any) => ({
|
.map((folder: QuarkShareInfo["list"][0]) => ({
|
||||||
fileId: folder.fid,
|
fileId: folder.fid,
|
||||||
fileName: folder.file_name,
|
fileName: folder.file_name,
|
||||||
fileIdToken: folder.share_fid_token,
|
fileIdToken: folder.share_fid_token,
|
||||||
@@ -89,7 +116,8 @@ export class QuarkService {
|
|||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
pwdId,
|
pwdId,
|
||||||
stoken: stoken,
|
stoken,
|
||||||
|
fileSize: response.data.data.share?.size || 0,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -98,7 +126,7 @@ export class QuarkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFolderList(parentCid = "0") {
|
async getFolderList(parentCid = "0"): Promise<FolderListResponse> {
|
||||||
const response = await this.api.get("/1/clouddrive/file/sort", {
|
const response = await this.api.get("/1/clouddrive/file/sort", {
|
||||||
params: {
|
params: {
|
||||||
pr: "ucpro",
|
pr: "ucpro",
|
||||||
@@ -114,10 +142,10 @@ export class QuarkService {
|
|||||||
__t: Date.now(),
|
__t: Date.now(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (response.data?.data && response.data.data.list.length) {
|
if (response.data?.data && response.data.data.list) {
|
||||||
const data = response.data.data.list
|
const data = response.data.data.list
|
||||||
.filter((item: any) => item.fid && item.file_type === 0)
|
.filter((item: QuarkFolderItem) => item.fid && item.file_type === 0)
|
||||||
.map((folder: any) => ({
|
.map((folder: QuarkFolderItem) => ({
|
||||||
cid: folder.fid,
|
cid: folder.fid,
|
||||||
name: folder.file_name,
|
name: folder.file_name,
|
||||||
path: [],
|
path: [],
|
||||||
@@ -127,24 +155,25 @@ export class QuarkService {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const message = "获取夸克目录列表失败:" + response.data.error;
|
const message = "获取夸克目录列表失败:" + response.data.error;
|
||||||
Logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSharedFile(params: {
|
async saveSharedFile(params: SaveFileParams): Promise<{ message: string; data: unknown }> {
|
||||||
fid_list: string[];
|
const quarkParams = {
|
||||||
fid_token_list: string[];
|
fid_list: params.fids,
|
||||||
to_pdir_fid: string;
|
fid_token_list: params.fidTokens,
|
||||||
pwd_id: string;
|
to_pdir_fid: params.folderId,
|
||||||
stoken: string;
|
pwd_id: params.shareCode,
|
||||||
pdir_fid: string;
|
stoken: params.receiveCode,
|
||||||
scene: string;
|
pdir_fid: "0",
|
||||||
}) {
|
scene: "link",
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const response = await this.api.post(
|
const response = await this.api.post(
|
||||||
`/1/clouddrive/share/sharepage/save?pr=ucpro&fr=pc&uc_param_str=&__dt=208097&__t=${Date.now()}`,
|
`/1/clouddrive/share/sharepage/save?pr=ucpro&fr=pc&uc_param_str=&__dt=208097&__t=${Date.now()}`,
|
||||||
params
|
quarkParams
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
import RSSParser from "rss-parser";
|
|
||||||
import { AxiosInstance, AxiosHeaders } from "axios";
|
|
||||||
import { config } from "../config";
|
|
||||||
import { Logger } from "../utils/logger";
|
|
||||||
import { createAxiosInstance } from "../utils/axiosInstance";
|
|
||||||
import { data } from "cheerio/dist/commonjs/api/attributes";
|
|
||||||
|
|
||||||
interface RSSItem {
|
|
||||||
title?: string;
|
|
||||||
link?: string;
|
|
||||||
pubDate?: string;
|
|
||||||
content?: string;
|
|
||||||
description?: string;
|
|
||||||
image?: string;
|
|
||||||
cloudLinks?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export class RSSSearcher {
|
|
||||||
private parser: RSSParser;
|
|
||||||
private axiosInstance: AxiosInstance;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.parser = new RSSParser({
|
|
||||||
customFields: {
|
|
||||||
item: [
|
|
||||||
["content:encoded", "content"],
|
|
||||||
["description", "description"],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.axiosInstance = createAxiosInstance(
|
|
||||||
config.rss.baseUrl,
|
|
||||||
AxiosHeaders.from({
|
|
||||||
"User-Agent":
|
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
||||||
Accept: "application/xml,application/xhtml+xml,text/html,application/rss+xml",
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private extractCloudLinks(text: string): { links: string[]; cloudType: string } {
|
|
||||||
const links: string[] = [];
|
|
||||||
let cloudType = "";
|
|
||||||
Object.values(config.cloudPatterns).forEach((pattern, index) => {
|
|
||||||
const matches = text.match(pattern);
|
|
||||||
if (matches) {
|
|
||||||
links.push(...matches);
|
|
||||||
cloudType = Object.keys(config.cloudPatterns)[index];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
links: [...new Set(links)],
|
|
||||||
cloudType,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async searchAll(keyword: string) {
|
|
||||||
const allResults = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < config.rss.channels.length; i++) {
|
|
||||||
const channel = config.rss.channels[i];
|
|
||||||
try {
|
|
||||||
const rssUrl = `${config.rss.baseUrl}/${
|
|
||||||
channel.id
|
|
||||||
}${keyword ? `/searchQuery=${encodeURIComponent(keyword)}` : ""}`;
|
|
||||||
|
|
||||||
const results = await this.searchInRSSFeed(rssUrl);
|
|
||||||
if (results.items.length > 0) {
|
|
||||||
const channelResults = results.items
|
|
||||||
.filter((item: RSSItem) => item.cloudLinks && item.cloudLinks.length > 0)
|
|
||||||
.map((item: RSSItem) => ({
|
|
||||||
...item,
|
|
||||||
channel: channel.name + "(" + channel.id + ")",
|
|
||||||
}));
|
|
||||||
|
|
||||||
allResults.push(...channelResults);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error(`搜索频道 ${channel.name} 失败:`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: allResults,
|
|
||||||
message: "搜索成功",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async searchInRSSFeed(rssUrl: string) {
|
|
||||||
try {
|
|
||||||
const response = await this.axiosInstance.get(rssUrl);
|
|
||||||
const feed = await this.parser.parseString(response.data);
|
|
||||||
|
|
||||||
return {
|
|
||||||
items: feed.items.map((item: RSSItem) => {
|
|
||||||
const linkInfo = this.extractCloudLinks(item.content || item.description || "");
|
|
||||||
return {
|
|
||||||
title: item.title || "",
|
|
||||||
link: item.link || "",
|
|
||||||
pubDate: item.pubDate || "",
|
|
||||||
image: item.image || "",
|
|
||||||
cloudLinks: linkInfo.links,
|
|
||||||
cloudType: linkInfo.cloudType,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error(`RSS源解析错误: ${rssUrl}`, error);
|
|
||||||
return {
|
|
||||||
items: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,8 @@ import GlobalSetting from "../models/GlobalSetting";
|
|||||||
import { GlobalSettingAttributes } from "../models/GlobalSetting";
|
import { GlobalSettingAttributes } from "../models/GlobalSetting";
|
||||||
import * as cheerio from "cheerio";
|
import * as cheerio from "cheerio";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
import { Logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
import { injectable } from "inversify";
|
||||||
|
|
||||||
interface sourceItem {
|
interface sourceItem {
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
@@ -20,20 +21,23 @@ interface sourceItem {
|
|||||||
cloudType?: string;
|
cloudType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
export class Searcher {
|
export class Searcher {
|
||||||
private axiosInstance: AxiosInstance | null = null;
|
private static instance: Searcher;
|
||||||
|
private api: AxiosInstance | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initializeAxiosInstance();
|
this.initAxiosInstance();
|
||||||
|
Searcher.instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializeAxiosInstance(isUpdate = false) {
|
private async initAxiosInstance(isUpdate: boolean = false) {
|
||||||
let settings = null;
|
let globalSetting = {} as GlobalSettingAttributes;
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
settings = await GlobalSetting.findOne();
|
const settings = await GlobalSetting.findOne();
|
||||||
|
globalSetting = settings?.dataValues || ({} as GlobalSettingAttributes);
|
||||||
}
|
}
|
||||||
const globalSetting = settings?.dataValues || ({} as GlobalSettingAttributes);
|
this.api = createAxiosInstance(
|
||||||
this.axiosInstance = createAxiosInstance(
|
|
||||||
config.telegram.baseUrl,
|
config.telegram.baseUrl,
|
||||||
AxiosHeaders.from({
|
AxiosHeaders.from({
|
||||||
accept:
|
accept:
|
||||||
@@ -56,8 +60,9 @@ export class Searcher {
|
|||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public async updateAxiosInstance() {
|
|
||||||
await this.initializeAxiosInstance(true);
|
public static async updateAxiosInstance(): Promise<void> {
|
||||||
|
await Searcher.instance.initAxiosInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractCloudLinks(text: string): { links: string[]; cloudType: string } {
|
private extractCloudLinks(text: string): { links: string[]; cloudType: string } {
|
||||||
@@ -67,7 +72,7 @@ export class Searcher {
|
|||||||
const matches = text.match(pattern);
|
const matches = text.match(pattern);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
links.push(...matches);
|
links.push(...matches);
|
||||||
cloudType = Object.keys(config.cloudPatterns)[index];
|
if (!cloudType) cloudType = Object.keys(config.cloudPatterns)[index];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
@@ -77,55 +82,58 @@ export class Searcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async searchAll(keyword: string, channelId?: string, messageId?: string) {
|
async searchAll(keyword: string, channelId?: string, messageId?: string) {
|
||||||
const allResults = [];
|
const allResults: any[] = [];
|
||||||
const totalChannels = config.rss.channels.length;
|
|
||||||
|
|
||||||
const channelList = channelId
|
const channelList: any[] = channelId
|
||||||
? config.rss.channels.filter((channel) => channel.id === channelId)
|
? config.telegram.channels.filter((channel: any) => channel.id === channelId)
|
||||||
: config.rss.channels;
|
: config.telegram.channels;
|
||||||
|
|
||||||
for (let i = 0; i < channelList.length; i++) {
|
// 使用Promise.all进行并行请求
|
||||||
const channel = channelList[i];
|
const searchPromises = channelList.map(async (channel) => {
|
||||||
try {
|
try {
|
||||||
const messageIdparams = messageId ? `before=${messageId}` : "";
|
const messageIdparams = messageId ? `before=${messageId}` : "";
|
||||||
const url = `/${channel.id}${keyword ? `?q=${encodeURIComponent(keyword)}&${messageIdparams}` : `?${messageIdparams}`}`;
|
const url = `/${channel.id}${keyword ? `?q=${encodeURIComponent(keyword)}&${messageIdparams}` : `?${messageIdparams}`}`;
|
||||||
console.log(`Searching in channel ${channel.name} with URL: ${url}`);
|
console.log(`Searching in channel ${channel.name} with URL: ${url}`);
|
||||||
const results = await this.searchInWeb(url, channel.id);
|
return this.searchInWeb(url).then((results) => {
|
||||||
console.log(`Found ${results.items.length} items in channel ${channel.name}`);
|
console.log(`Found ${results.items.length} items in channel ${channel.name}`);
|
||||||
if (results.items.length > 0) {
|
if (results.items.length > 0) {
|
||||||
const channelResults = results.items
|
const channelResults = results.items
|
||||||
.filter((item: sourceItem) => item.cloudLinks && item.cloudLinks.length > 0)
|
.filter((item: sourceItem) => item.cloudLinks && item.cloudLinks.length > 0)
|
||||||
.map((item: sourceItem) => ({
|
.map((item: sourceItem) => ({
|
||||||
...item,
|
...item,
|
||||||
channel: channel.name,
|
channel: channel.name,
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
allResults.push({
|
allResults.push({
|
||||||
list: channelResults,
|
list: channelResults,
|
||||||
channelInfo: {
|
channelInfo: {
|
||||||
...channel,
|
...channel,
|
||||||
channelLogo: results.channelLogo,
|
channelLogo: results.channelLogo,
|
||||||
},
|
},
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`搜索频道 ${channel.name} 失败:`, error);
|
logger.error(`搜索频道 ${channel.name} 失败:`, error);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// 等待所有请求完成
|
||||||
|
await Promise.all(searchPromises);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: allResults,
|
data: allResults,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchInWeb(url: string, channelId: string) {
|
async searchInWeb(url: string) {
|
||||||
try {
|
try {
|
||||||
if (!this.axiosInstance) {
|
if (!this.api) {
|
||||||
throw new Error("Axios instance is not initialized");
|
throw new Error("Axios instance is not initialized");
|
||||||
}
|
}
|
||||||
const response = await this.axiosInstance.get(url);
|
const response = await this.api.get(url);
|
||||||
const html = response.data;
|
const html = response.data;
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
const items: sourceItem[] = [];
|
const items: sourceItem[] = [];
|
||||||
@@ -202,7 +210,7 @@ export class Searcher {
|
|||||||
});
|
});
|
||||||
return { items: items, channelLogo };
|
return { items: items, channelLogo };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`搜索错误: ${url}`, error);
|
logger.error(`搜索错误: ${url}`, error);
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [],
|
||||||
channelLogo: "",
|
channelLogo: "",
|
||||||
|
|||||||
59
backend/src/services/SettingService.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { injectable, inject } from "inversify";
|
||||||
|
import { TYPES } from "../core/types";
|
||||||
|
import UserSetting from "../models/UserSetting";
|
||||||
|
import GlobalSetting from "../models/GlobalSetting";
|
||||||
|
import { Searcher } from "./Searcher";
|
||||||
|
import { ImageService } from "./ImageService";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class SettingService {
|
||||||
|
constructor(@inject(TYPES.ImageService) private imageService: ImageService) {}
|
||||||
|
|
||||||
|
async getSettings(userId: string | undefined, role: number | undefined) {
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error("用户ID无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
let userSettings = await UserSetting.findOne({ where: { userId: userId.toString() } });
|
||||||
|
if (!userSettings) {
|
||||||
|
userSettings = await UserSetting.create({
|
||||||
|
userId: userId.toString(),
|
||||||
|
cloud115Cookie: "",
|
||||||
|
quarkCookie: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalSetting = await GlobalSetting.findOne();
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
userSettings,
|
||||||
|
globalSetting: role === 1 ? globalSetting : null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveSettings(userId: string | undefined, role: number | undefined, settings: any) {
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error("用户ID无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
const { userSettings, globalSetting } = settings;
|
||||||
|
await UserSetting.update(userSettings, { where: { userId: userId.toString() } });
|
||||||
|
|
||||||
|
if (role === 1 && globalSetting) {
|
||||||
|
await GlobalSetting.update(globalSetting, { where: {} });
|
||||||
|
}
|
||||||
|
await this.updateSettings();
|
||||||
|
return { message: "保存成功" };
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateSettings(/* 参数 */): Promise<void> {
|
||||||
|
// ... 其他代码 ...
|
||||||
|
|
||||||
|
// 修改这一行,使用注入的实例方法而不是静态方法
|
||||||
|
await this.imageService.updateAxiosInstance();
|
||||||
|
await Searcher.updateAxiosInstance();
|
||||||
|
|
||||||
|
// ... 其他代码 ...
|
||||||
|
}
|
||||||
|
}
|
||||||
25
backend/src/services/SponsorsService.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { injectable } from "inversify";
|
||||||
|
import { createAxiosInstance } from "../utils/axiosInstance";
|
||||||
|
import { AxiosInstance } from "axios";
|
||||||
|
import sponsors from "../sponsors/sponsors.json";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class SponsorsService {
|
||||||
|
private axiosInstance: AxiosInstance;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.axiosInstance = createAxiosInstance("http://oss.jiangmuxin.cn/cloudsaver/");
|
||||||
|
}
|
||||||
|
async getSponsors() {
|
||||||
|
try {
|
||||||
|
const response = await this.axiosInstance.get("sponsors.json");
|
||||||
|
return {
|
||||||
|
data: response.data.sponsors,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
data: sponsors.sponsors,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
63
backend/src/services/UserService.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { injectable } from "inversify";
|
||||||
|
import bcrypt from "bcrypt";
|
||||||
|
import jwt from "jsonwebtoken";
|
||||||
|
import { config } from "../config";
|
||||||
|
import User from "../models/User";
|
||||||
|
import GlobalSetting from "../models/GlobalSetting";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UserService {
|
||||||
|
private isValidInput(input: string): boolean {
|
||||||
|
// 检查是否包含空格或汉字
|
||||||
|
const regex = /^[^\s\u4e00-\u9fa5]+$/;
|
||||||
|
return regex.test(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
async register(username: string, password: string, registerCode: string) {
|
||||||
|
const globalSetting = await GlobalSetting.findOne();
|
||||||
|
const registerCodeList = [
|
||||||
|
globalSetting?.dataValues.CommonUserCode,
|
||||||
|
globalSetting?.dataValues.AdminUserCode,
|
||||||
|
];
|
||||||
|
if (!registerCode || !registerCodeList.includes(Number(registerCode))) {
|
||||||
|
throw new Error("注册码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证输入
|
||||||
|
if (!this.isValidInput(username) || !this.isValidInput(password)) {
|
||||||
|
throw new Error("用户名、密码或注册码不能包含空格或汉字");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查用户名是否已存在
|
||||||
|
const existingUser = await User.findOne({ where: { username } });
|
||||||
|
if (existingUser) {
|
||||||
|
throw new Error("用户名已存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
|
const role = registerCodeList.findIndex((x) => x === Number(registerCode));
|
||||||
|
const user = await User.create({ username, password: hashedPassword, role });
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: user,
|
||||||
|
message: "用户注册成功",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async login(username: string, password: string) {
|
||||||
|
const user = await User.findOne({ where: { username } });
|
||||||
|
if (!user || !(await bcrypt.compare(password, user.password))) {
|
||||||
|
throw new Error("用户名或密码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = jwt.sign({ userId: user.userId, role: user.role }, config.jwtSecret, {
|
||||||
|
expiresIn: "6h",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
54
backend/src/sponsors/sponsors.json
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"sponsors": [
|
||||||
|
{
|
||||||
|
"name": "立本狗头",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks1.jpg",
|
||||||
|
"message": "怒搓楼上狗头! "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "帝国鼻屎",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks2.jpg",
|
||||||
|
"message": "芜湖起飞! "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "雷霆222",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks3.jpg",
|
||||||
|
"message": "把我弄帅点 "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "黑田奈奈子",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks4.jpg",
|
||||||
|
"message": "流年笑掷 未来可期 ",
|
||||||
|
"link": "https://github.com/htnanako"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "原野🐇",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks5.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "我摆烂!",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks6.jpg",
|
||||||
|
"message": "人生苦短,及时行乐,卷什么卷,随缘摆烂 "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "田培",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks7.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "River",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks8.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "午夜学徒",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks9.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "阿潘",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks10.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "闹闹黑",
|
||||||
|
"avatar": "http://oss.jiangmuxin.cn/cloudsaver/sponsors/thanks11.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
83
backend/src/types/cloud.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
export interface ShareInfoResponse {
|
||||||
|
data: {
|
||||||
|
list: ShareInfoItem[];
|
||||||
|
fileSize?: number;
|
||||||
|
pwdId?: string;
|
||||||
|
stoken?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetShareInfoParams {
|
||||||
|
shareCode: string;
|
||||||
|
receiveCode?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ShareInfoItem {
|
||||||
|
fileId: string;
|
||||||
|
fileName: string;
|
||||||
|
fileSize?: number;
|
||||||
|
fileIdToken?: string;
|
||||||
|
}
|
||||||
|
export interface FolderListResponse {
|
||||||
|
data: {
|
||||||
|
cid: string;
|
||||||
|
name: string;
|
||||||
|
path: { cid: string; name: string }[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SaveFileParams {
|
||||||
|
shareCode: string; // 分享code
|
||||||
|
receiveCode?: string; // 分享文件的密码
|
||||||
|
folderId?: string; // 文件夹id
|
||||||
|
fids?: string[]; // 存储文件id
|
||||||
|
fidTokens?: string[]; // 存储文件token
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SaveFileResponse {
|
||||||
|
message: string;
|
||||||
|
data: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ShareFileInfo {
|
||||||
|
shareCode: string;
|
||||||
|
receiveCode?: string;
|
||||||
|
fileId: string;
|
||||||
|
cid?: string;
|
||||||
|
fid_list?: string[];
|
||||||
|
fid_token_list?: string[];
|
||||||
|
to_pdir_fid?: string;
|
||||||
|
pwd_id?: string;
|
||||||
|
stoken?: string;
|
||||||
|
pdir_fid?: string;
|
||||||
|
scene?: string;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QuarkShareFileInfo {
|
||||||
|
fid_list: string[];
|
||||||
|
fid_token_list: string[];
|
||||||
|
to_pdir_fid: string;
|
||||||
|
pwd_id: string;
|
||||||
|
stoken: string;
|
||||||
|
pdir_fid: string;
|
||||||
|
scene: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QuarkShareInfo {
|
||||||
|
stoken?: string;
|
||||||
|
pwdId?: string;
|
||||||
|
fileSize?: number;
|
||||||
|
list: {
|
||||||
|
fid: string;
|
||||||
|
file_name: string;
|
||||||
|
file_type: number;
|
||||||
|
share_fid_token: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QuarkFolderItem {
|
||||||
|
fid: string;
|
||||||
|
file_name: string;
|
||||||
|
file_type: number;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
|
|
||||||
declare module "express" {
|
declare module "express" {
|
||||||
|
|||||||
15
backend/src/types/index.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export interface Config {
|
||||||
|
app: {
|
||||||
|
port: number;
|
||||||
|
env: string;
|
||||||
|
};
|
||||||
|
database: {
|
||||||
|
type: string;
|
||||||
|
path: string;
|
||||||
|
};
|
||||||
|
jwt: {
|
||||||
|
secret: string;
|
||||||
|
expiresIn: string;
|
||||||
|
};
|
||||||
|
// ... 其他配置类型
|
||||||
|
}
|
||||||
9
backend/src/types/services.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Request } from "express";
|
||||||
|
import { ShareInfoResponse, FolderListResponse, SaveFileParams } from "./cloud";
|
||||||
|
|
||||||
|
export interface ICloudStorageService {
|
||||||
|
setCookie(req: Request): Promise<void>;
|
||||||
|
getShareInfo(shareCode: string, receiveCode?: string): Promise<ShareInfoResponse>;
|
||||||
|
getFolderList(parentCid?: string): Promise<FolderListResponse>;
|
||||||
|
saveSharedFile(params: SaveFileParams): Promise<any>;
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import axios, { AxiosInstance, AxiosRequestHeaders } from "axios";
|
import axios, { AxiosInstance, AxiosRequestHeaders } from "axios";
|
||||||
import tunnel from "tunnel";
|
import tunnel from "tunnel";
|
||||||
import { config } from "../config";
|
|
||||||
import GlobalSetting from "../models/GlobalSetting";
|
|
||||||
|
|
||||||
interface ProxyConfig {
|
interface ProxyConfig {
|
||||||
host: string;
|
host: string;
|
||||||
@@ -10,12 +8,11 @@ interface ProxyConfig {
|
|||||||
|
|
||||||
export function createAxiosInstance(
|
export function createAxiosInstance(
|
||||||
baseURL: string,
|
baseURL: string,
|
||||||
headers: AxiosRequestHeaders,
|
headers?: AxiosRequestHeaders,
|
||||||
useProxy: boolean = false,
|
useProxy: boolean = false,
|
||||||
proxyConfig?: ProxyConfig
|
proxyConfig?: ProxyConfig
|
||||||
): AxiosInstance {
|
): AxiosInstance {
|
||||||
let agent;
|
let agent;
|
||||||
console.log(proxyConfig);
|
|
||||||
if (useProxy && proxyConfig) {
|
if (useProxy && proxyConfig) {
|
||||||
agent = tunnel.httpsOverHttp({
|
agent = tunnel.httpsOverHttp({
|
||||||
proxy: proxyConfig,
|
proxy: proxyConfig,
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import { Response, NextFunction } from "express";
|
import { Response, NextFunction } from "express";
|
||||||
import { Logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
|
|
||||||
|
interface CustomError {
|
||||||
|
name?: string;
|
||||||
|
message: string;
|
||||||
|
success?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export default function handleError(
|
export default function handleError(
|
||||||
res: Response,
|
res: Response,
|
||||||
error: any,
|
error: CustomError | unknown,
|
||||||
message: string,
|
message: string,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) {
|
) {
|
||||||
Logger.error(message, error);
|
logger.error(message, error);
|
||||||
next(error || { success: false, message });
|
next(error || { success: false, message });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +1,21 @@
|
|||||||
type LogLevel = "info" | "success" | "warn" | "error";
|
import winston from "winston";
|
||||||
|
import { config } from "../config";
|
||||||
|
|
||||||
export const Logger = {
|
const logger = winston.createLogger({
|
||||||
info(...args: any[]) {
|
level: config.app.env === "development" ? "debug" : "info",
|
||||||
this.log("info", ...args);
|
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
|
||||||
},
|
transports: [
|
||||||
|
new winston.transports.File({ filename: "logs/error.log", level: "error" }),
|
||||||
|
new winston.transports.File({ filename: "logs/combined.log" }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
success(...args: any[]) {
|
if (config.app.env !== "production") {
|
||||||
this.log("success", ...args);
|
logger.add(
|
||||||
},
|
new winston.transports.Console({
|
||||||
|
format: winston.format.simple(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
warn(...args: any[]) {
|
export { logger };
|
||||||
this.log("warn", ...args);
|
|
||||||
},
|
|
||||||
|
|
||||||
error(...args: any[]) {
|
|
||||||
this.log("error", ...args);
|
|
||||||
},
|
|
||||||
|
|
||||||
log(level: LogLevel, ...args: any[]) {
|
|
||||||
const timestamp = new Date().toISOString();
|
|
||||||
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
|
|
||||||
|
|
||||||
switch (level) {
|
|
||||||
case "success":
|
|
||||||
console.log(prefix, ...args);
|
|
||||||
break;
|
|
||||||
case "warn":
|
|
||||||
console.warn(prefix, ...args);
|
|
||||||
break;
|
|
||||||
case "error":
|
|
||||||
console.error(prefix, ...args);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log(prefix, ...args);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
"typeRoots": ["./node_modules/@types", "./src/types"],
|
"typeRoots": ["./node_modules/@types", "./src/types"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
}
|
},
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
|
|||||||
13
docker-entrypoint.sh
Normal file
@@ -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
|
||||||
|
Before Width: | Height: | Size: 162 KiB |
|
Before Width: | Height: | Size: 172 KiB |
BIN
docs/images/alipay.png
Normal file
|
After Width: | Height: | Size: 610 KiB |
|
Before Width: | Height: | Size: 2.4 MiB |
|
Before Width: | Height: | Size: 1.2 MiB |
BIN
docs/images/mobile/douban.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
BIN
docs/images/mobile/login.png
Normal file
|
After Width: | Height: | Size: 631 KiB |
BIN
docs/images/mobile/save.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
docs/images/mobile/save1.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
docs/images/mobile/search.png
Normal file
|
After Width: | Height: | Size: 470 KiB |
BIN
docs/images/pc/detail.png
Normal file
|
After Width: | Height: | Size: 674 KiB |
BIN
docs/images/pc/douban.png
Normal file
|
After Width: | Height: | Size: 2.4 MiB |
BIN
docs/images/pc/login.png
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
BIN
docs/images/pc/save.png
Normal file
|
After Width: | Height: | Size: 314 KiB |
BIN
docs/images/pc/save1.png
Normal file
|
After Width: | Height: | Size: 311 KiB |
BIN
docs/images/pc/search.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 195 KiB |
|
Before Width: | Height: | Size: 186 KiB |
|
Before Width: | Height: | Size: 139 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 824 KiB |
|
Before Width: | Height: | Size: 86 KiB |
BIN
docs/images/wechat.jpg
Normal file
|
After Width: | Height: | Size: 181 KiB |
BIN
docs/images/wechat_2.jpg
Normal file
|
After Width: | Height: | Size: 163 KiB |
BIN
docs/images/wechat_pay.jpg
Normal file
|
After Width: | Height: | Size: 74 KiB |
1
frontend/auto-imports.d.ts
vendored
@@ -6,4 +6,5 @@
|
|||||||
export {}
|
export {}
|
||||||
declare global {
|
declare global {
|
||||||
const ElMessage: typeof import('element-plus/es')['ElMessage']
|
const ElMessage: typeof import('element-plus/es')['ElMessage']
|
||||||
|
const showConfirmDialog: typeof import('vant/es')['showConfirmDialog']
|
||||||
}
|
}
|
||||||
|
|||||||
30
frontend/components.d.ts
vendored
@@ -8,13 +8,11 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
AsideMenu: typeof import('./src/components/AsideMenu.vue')['default']
|
AsideMenu: typeof import('./src/components/AsideMenu.vue')['default']
|
||||||
DoubanMovie: typeof import('./src/components/Home/DoubanMovie.vue')['default']
|
|
||||||
ElAside: typeof import('element-plus/es')['ElAside']
|
ElAside: typeof import('element-plus/es')['ElAside']
|
||||||
ElBacktop: typeof import('element-plus/es')['ElBacktop']
|
ElBacktop: typeof import('element-plus/es')['ElBacktop']
|
||||||
ElButton: typeof import('element-plus/es')['ElButton']
|
ElButton: typeof import('element-plus/es')['ElButton']
|
||||||
ElCard: typeof import('element-plus/es')['ElCard']
|
ElCard: typeof import('element-plus/es')['ElCard']
|
||||||
ElCheckbox: (typeof import("element-plus/es"))["ElCheckbox"]
|
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
|
||||||
ElCol: typeof import('element-plus/es')['ElCol']
|
|
||||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||||
ElContainer: typeof import('element-plus/es')['ElContainer']
|
ElContainer: typeof import('element-plus/es')['ElContainer']
|
||||||
ElDialog: typeof import('element-plus/es')['ElDialog']
|
ElDialog: typeof import('element-plus/es')['ElDialog']
|
||||||
@@ -30,8 +28,6 @@ declare module 'vue' {
|
|||||||
ElMain: typeof import('element-plus/es')['ElMain']
|
ElMain: typeof import('element-plus/es')['ElMain']
|
||||||
ElMenu: typeof import('element-plus/es')['ElMenu']
|
ElMenu: typeof import('element-plus/es')['ElMenu']
|
||||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||||
ElMenuItemGroup: typeof import('element-plus/es')['ElMenuItemGroup']
|
|
||||||
ElRow: typeof import('element-plus/es')['ElRow']
|
|
||||||
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
||||||
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
||||||
ElTable: typeof import('element-plus/es')['ElTable']
|
ElTable: typeof import('element-plus/es')['ElTable']
|
||||||
@@ -40,14 +36,34 @@ declare module 'vue' {
|
|||||||
ElTabs: typeof import('element-plus/es')['ElTabs']
|
ElTabs: typeof import('element-plus/es')['ElTabs']
|
||||||
ElTag: typeof import('element-plus/es')['ElTag']
|
ElTag: typeof import('element-plus/es')['ElTag']
|
||||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||||
ElTree: typeof import('element-plus/es')['ElTree']
|
|
||||||
FolderSelect: typeof import('./src/components/Home/FolderSelect.vue')['default']
|
FolderSelect: typeof import('./src/components/Home/FolderSelect.vue')['default']
|
||||||
ResourceCard: typeof import('./src/components/Home/ResourceCard.vue')['default']
|
ResourceCard: typeof import('./src/components/Home/ResourceCard.vue')['default']
|
||||||
ResourceList: typeof import('./src/components/Home/ResourceList.vue')['default']
|
ResourceSelect: typeof import('./src/components/Home/ResourceSelect.vue')['default']
|
||||||
ResourceTable: typeof import('./src/components/Home/ResourceTable.vue')['default']
|
ResourceTable: typeof import('./src/components/Home/ResourceTable.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
SearchBar: typeof import('./src/components/SearchBar.vue')['default']
|
SearchBar: typeof import('./src/components/SearchBar.vue')['default']
|
||||||
|
VanBackTop: typeof import('vant/es')['BackTop']
|
||||||
|
VanButton: typeof import('vant/es')['Button']
|
||||||
|
VanCell: typeof import('vant/es')['Cell']
|
||||||
|
VanCellGroup: typeof import('vant/es')['CellGroup']
|
||||||
|
VanCheckbox: typeof import('vant/es')['Checkbox']
|
||||||
|
VanCheckboxGroup: typeof import('vant/es')['CheckboxGroup']
|
||||||
|
VanEmpty: typeof import('vant/es')['Empty']
|
||||||
|
VanField: typeof import('vant/es')['Field']
|
||||||
|
VanForm: typeof import('vant/es')['Form']
|
||||||
|
VanIcon: typeof import('vant/es')['Icon']
|
||||||
|
VanImage: typeof import('vant/es')['Image']
|
||||||
|
VanLoading: typeof import('vant/es')['Loading']
|
||||||
|
VanOverlay: typeof import('vant/es')['Overlay']
|
||||||
|
VanPopup: typeof import('vant/es')['Popup']
|
||||||
|
VanSearch: typeof import('vant/es')['Search']
|
||||||
|
VanSwitch: typeof import('vant/es')['Switch']
|
||||||
|
VanTab: typeof import('vant/es')['Tab']
|
||||||
|
VanTabbar: typeof import('vant/es')['Tabbar']
|
||||||
|
VanTabbarItem: typeof import('vant/es')['TabbarItem']
|
||||||
|
VanTabs: typeof import('vant/es')['Tabs']
|
||||||
|
VanTag: typeof import('vant/es')['Tag']
|
||||||
}
|
}
|
||||||
export interface ComponentCustomProperties {
|
export interface ComponentCustomProperties {
|
||||||
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
|
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
|
||||||
|
|||||||
@@ -8,6 +8,30 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
|
||||||
/>
|
/>
|
||||||
|
<meta name="keywords" content="网盘,资源搜索,云存储" />
|
||||||
|
<!-- SEO关键词 -->
|
||||||
|
<meta name="description" content="网盘资源搜索工具" />
|
||||||
|
<!-- 设置Web App描述 -->
|
||||||
|
<meta name="theme-color" content="#ffffff" />
|
||||||
|
<!-- 设置主题颜色 -->
|
||||||
|
<meta property="og:title" content="CloudSaver" />
|
||||||
|
<!-- 社交媒体分享标题 -->
|
||||||
|
<meta property="og:description" content="网盘资源搜索工具" />
|
||||||
|
<!-- 社交媒体分享描述 -->
|
||||||
|
<meta property="og:url" content="https://github.com/jiangrui1994/CloudSaver" />
|
||||||
|
<!-- 社交媒体分享链接 -->
|
||||||
|
<meta name="twitter:card" content="summary" />
|
||||||
|
<!-- Twitter卡片类型 -->
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<!-- 开启Web App功能 -->
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
|
<!-- 设置状态栏样式 -->
|
||||||
|
<meta name="apple-mobile-web-app-title" content="CloudSaver" />
|
||||||
|
<!-- 设置Web App标题 -->
|
||||||
|
<link rel="apple-touch-icon" href="/logo-1.png" />
|
||||||
|
<!-- 设置Web App图标 -->
|
||||||
|
<link rel="mask-icon" href="/logo.svg" color="transparent" />
|
||||||
|
<!-- 设置Web App图标遮罩 -->
|
||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
<title>CloudSaver</title>
|
<title>CloudSaver</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
BIN
frontend/logo-1.png
Normal file
|
After Width: | Height: | Size: 248 KiB |
3751
frontend/logo.svg
Normal file
|
After Width: | Height: | Size: 282 KiB |
4
frontend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cloud-disk-web",
|
"name": "cloud-disk-web",
|
||||||
"version": "0.1.0",
|
"version": "0.2.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cloud-disk-web",
|
"name": "cloud-disk-web",
|
||||||
"version": "0.1.0",
|
"version": "0.2.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.6.7",
|
||||||
"element-plus": "^2.6.1",
|
"element-plus": "^2.6.1",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "cloud-saver-web",
|
"name": "cloud-saver-web",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0",
|
"version": "0.2.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --host",
|
"dev": "vite --host",
|
||||||
@@ -12,19 +12,25 @@
|
|||||||
"@element-plus/icons-vue": "^2.3.1",
|
"@element-plus/icons-vue": "^2.3.1",
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.6.7",
|
||||||
"element-plus": "^2.6.1",
|
"element-plus": "^2.6.1",
|
||||||
|
"gsap": "^3.12.7",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"socket.io-client": "^4.8.1",
|
"socket.io-client": "^4.8.1",
|
||||||
|
"typeit": "^8.8.7",
|
||||||
|
"vant": "^4.9.17",
|
||||||
"vue": "^3.4.21",
|
"vue": "^3.4.21",
|
||||||
"vue-router": "^4.3.0"
|
"vue-router": "^4.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.11.25",
|
"@types/node": "^20.11.25",
|
||||||
|
"@vant/auto-import-resolver": "^1.3.0",
|
||||||
"@vitejs/plugin-vue": "^5.0.4",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
|
"postcss-pxtorem": "^6.1.0",
|
||||||
"sass": "^1.83.4",
|
"sass": "^1.83.4",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.4.2",
|
||||||
"unplugin-auto-import": "^0.17.5",
|
"unplugin-auto-import": "^0.17.8",
|
||||||
"unplugin-vue-components": "^0.26.0",
|
"unplugin-vue-components": "^0.26.0",
|
||||||
"vite": "^5.1.5",
|
"vite": "^5.1.5",
|
||||||
|
"vite-plugin-pwa": "^0.21.1",
|
||||||
"vue-tsc": "^2.0.6"
|
"vue-tsc": "^2.0.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
frontend/postcss.config.cjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
"postcss-pxtorem": {
|
||||||
|
rootValue({ file }) {
|
||||||
|
return file.indexOf("vant") !== -1 || file.indexOf("mobile") !== -1 ? 50 : 75;
|
||||||
|
},
|
||||||
|
propList: ["*"],
|
||||||
|
exclude: (file) => {
|
||||||
|
return !file.includes("mobile") && !file.includes("vant");
|
||||||
|
},
|
||||||
|
minPixelValue: 2,
|
||||||
|
mediaQuery: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -5,32 +5,69 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
#app {
|
||||||
|
height: 100vh;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
}
|
||||||
|
:root {
|
||||||
|
--theme-color: #3e3e3e;
|
||||||
|
--theme-theme: #133ab3;
|
||||||
|
--theme-background: #fafafa;
|
||||||
|
--theme-other_background: #ffffff;
|
||||||
|
}
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-family:
|
||||||
|
v-sans,
|
||||||
|
system-ui,
|
||||||
|
-apple-system,
|
||||||
|
BlinkMacSystemFont,
|
||||||
|
Segoe UI,
|
||||||
|
sans-serif,
|
||||||
|
"Apple Color Emoji",
|
||||||
|
"Segoe UI Emoji",
|
||||||
|
Segoe UI Symbol;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--theme-color);
|
||||||
|
background-color: var(--theme-background);
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移动端全局样式 */
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
#app {
|
#app {
|
||||||
height: 100vh;
|
max-width: 100vw;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
:root {
|
|
||||||
--theme-color: #3e3e3e;
|
/* 统一按钮样式 */
|
||||||
--theme-theme: #133ab3;
|
.van-button {
|
||||||
--theme-background: #fafafa;
|
height: 40px;
|
||||||
--theme-other_background: #ffffff;
|
font-size: var(--font-size-base);
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
}
|
}
|
||||||
html,
|
|
||||||
body {
|
/* 统一输入框样式 */
|
||||||
margin: 0;
|
.van-field {
|
||||||
font-size: 15px;
|
font-size: var(--font-size-base);
|
||||||
font-family:
|
|
||||||
v-sans,
|
|
||||||
system-ui,
|
|
||||||
-apple-system,
|
|
||||||
BlinkMacSystemFont,
|
|
||||||
Segoe UI,
|
|
||||||
sans-serif,
|
|
||||||
"Apple Color Emoji",
|
|
||||||
"Segoe UI Emoji",
|
|
||||||
Segoe UI Symbol;
|
|
||||||
line-height: 1.6;
|
|
||||||
color: var(--theme-color);
|
|
||||||
background-color: var(--theme-background);
|
|
||||||
word-wrap: break-word;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 统一卡片样式 */
|
||||||
|
.van-card {
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
margin: var(--spacing-base) 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
import type { ShareInfoResponse, Folder, Save115FileParams } from "@/types";
|
import type { ShareInfoResponse, Folder, SaveFileParams, GetShareInfoParams } from "@/types";
|
||||||
|
|
||||||
export const cloud115Api = {
|
export const cloud115Api = {
|
||||||
async getShareInfo(shareCode: string, receiveCode = "") {
|
async getShareInfo(params: GetShareInfoParams) {
|
||||||
const { data } = await request.get<ShareInfoResponse>("/api/cloud115/share-info", {
|
const { data } = await request.get<ShareInfoResponse>("/api/cloud115/share-info", {
|
||||||
params: { shareCode, receiveCode },
|
params,
|
||||||
});
|
});
|
||||||
return data as ShareInfoResponse;
|
return data as ShareInfoResponse;
|
||||||
},
|
},
|
||||||
@@ -16,7 +16,7 @@ export const cloud115Api = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveFile(params: Save115FileParams) {
|
async saveFile(params: SaveFileParams) {
|
||||||
const res = await request.post("/api/cloud115/save", params);
|
const res = await request.post("/api/cloud115/save", params);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
import type { ShareInfoResponse, Folder, SaveQuarkFileParams } from "@/types";
|
import type { ShareInfoResponse, Folder, SaveFileParams, GetShareInfoParams } from "@/types";
|
||||||
|
|
||||||
export const quarkApi = {
|
export const quarkApi = {
|
||||||
async getShareInfo(pwdId: string, passcode = "") {
|
async getShareInfo(params: GetShareInfoParams) {
|
||||||
const { data } = await request.get<ShareInfoResponse>("/api/quark/share-info", {
|
const { data } = await request.get<ShareInfoResponse>("/api/quark/share-info", {
|
||||||
params: { pwdId, passcode },
|
params,
|
||||||
});
|
});
|
||||||
return data as ShareInfoResponse;
|
return data as ShareInfoResponse;
|
||||||
},
|
},
|
||||||
@@ -16,7 +16,7 @@ export const quarkApi = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveFile(params: SaveQuarkFileParams) {
|
async saveFile(params: SaveFileParams) {
|
||||||
return await request.post("/api/quark/save", params);
|
return await request.post("/api/quark/save", params);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ export const userApi = {
|
|||||||
login: (data: { username: string; password: string }) => {
|
login: (data: { username: string; password: string }) => {
|
||||||
return request.post<{ token: string }>("/api/user/login", data);
|
return request.post<{ token: string }>("/api/user/login", data);
|
||||||
},
|
},
|
||||||
register: (data: { username: string; password: string }) => {
|
register: (data: { username: string; password: string; registerCode: string }) => {
|
||||||
return request.post<{ token: string }>("/api/user/register", data);
|
return request.post<{ token: string }>("/api/user/register", data);
|
||||||
},
|
},
|
||||||
|
getSponsors: () => {
|
||||||
|
return request.get("/api/sponsors?timestamp=" + Date.now());
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
BIN
frontend/src/assets/images/default.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |