From 8729025b04b9495cdb94ab7ad8e92a2ad5d1c923 Mon Sep 17 00:00:00 2001 From: kjqwer <2990346238@qq.com> Date: Fri, 22 Aug 2025 08:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8C=85=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 ++- README.md | 7 +++ backend/config/config-manager.js | 12 +++- backend/services/download.js | 13 ++++- package.json | 17 +++++- scripts/create-portable.js | 97 ++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 scripts/create-portable.js diff --git a/.gitignore b/.gitignore index dbe0134..53b0afe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -/test -/package-lock.json - # Logs logs *.log @@ -72,3 +69,7 @@ backend/config/user-config.json # 自己的启动文件 start_me.bat + +#打包文件夹 +dist/ +pixiv-manager-portable/ diff --git a/README.md b/README.md index 63f9552..6a647e7 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ Pixiv 下载浏览管理器是一个基于 Web 的应用程序,提供以下功 ## 🚀 快速开始 +### 便携版下载(如果不想自义定或者是懒) + +如果懒得配置环境,可以直接下载便携版: +- **下载链接**: https://pan.baidu.com/s/1pIdl8eqQSA8jc2RM7HoZfg?pwd=j18v +- **提取码**: j18v +- **使用说明**: 下载后解压,记事本打开start.bat配置代理(看readme有介绍),双击 `start.bat` 即可启动,打开网站,按照教程登录即可 + ### 环境要求 - **Node.js** (版本 >= 16.0.0) diff --git a/backend/config/config-manager.js b/backend/config/config-manager.js index 6810672..66c3bfe 100644 --- a/backend/config/config-manager.js +++ b/backend/config/config-manager.js @@ -7,7 +7,17 @@ const path = require('path') */ class ConfigManager { constructor() { - this.configDir = path.join(__dirname, 'user-config.json') + // 检测是否在pkg打包环境中运行 + const isPkg = process.pkg !== undefined; + + if (isPkg) { + // 在打包环境中,使用可执行文件所在目录 + this.configDir = path.join(process.cwd(), 'data', 'user-config.json') + } else { + // 在开发环境中,使用相对路径 + this.configDir = path.join(__dirname, 'user-config.json') + } + this.defaultConfig = { downloadDir: "./downloads", fileStructure: "artist/artwork", diff --git a/backend/services/download.js b/backend/services/download.js index 037fd09..ba08d97 100644 --- a/backend/services/download.js +++ b/backend/services/download.js @@ -12,7 +12,18 @@ class DownloadService { this.artworkService = new ArtworkService(auth); this.artistService = new ArtistService(auth); this.configManager = new ConfigManager(); - this.dataPath = path.join(__dirname, '../../data'); + + // 检测是否在pkg打包环境中运行 + const isPkg = process.pkg !== undefined; + + if (isPkg) { + // 在打包环境中,使用可执行文件所在目录 + this.dataPath = path.join(process.cwd(), 'data'); + } else { + // 在开发环境中,使用相对路径 + this.dataPath = path.join(__dirname, '../../data'); + } + this.tasksFile = path.join(this.dataPath, 'download_tasks.json'); this.historyFile = path.join(this.dataPath, 'download_history.json'); diff --git a/package.json b/package.json index 1a08268..1ed79eb 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,26 @@ { "name": "pixiv-backend", "version": "1.0.0", - "description": "Pixiv 后端服务 - 支持 OAuth 2.0 登录和 API 调用", + "description": "Pixiv 下载浏览管理器", "main": "backend/start.js", + "bin": "backend/start.js", + "pkg": { + "targets": ["node18-win-x64"], + "outputPath": "dist", + "assets": [ + "backend/**/*", + "ui/**/*", + "data/**/*", + "node_modules/**/*" + ] + }, "scripts": { "start": "node backend/start.js", "dev": "node backend/start.js", "test": "node backend/test-login.js", - "set-proxy": "node backend/set-proxy.js" + "set-proxy": "node backend/set-proxy.js", + "build": "pkg .", + "build-portable": "npm run build && node scripts/create-portable.js" }, "dependencies": { "appdata-path": "^1.0.0", diff --git a/scripts/create-portable.js b/scripts/create-portable.js new file mode 100644 index 0000000..7813a30 --- /dev/null +++ b/scripts/create-portable.js @@ -0,0 +1,97 @@ +const fs = require('fs-extra'); +const path = require('path'); + +async function createPortable() { + const distDir = path.join(__dirname, '..', 'dist'); + const portableDir = path.join(__dirname, '..', 'pixiv-manager-portable'); + + try { + // 清理之前的便携版 + await fs.remove(portableDir); + await fs.ensureDir(portableDir); + + // 复制可执行文件 + const exeName = 'pixiv-backend.exe'; + const exePath = path.join(distDir, exeName); + if (await fs.pathExists(exePath)) { + await fs.copy(exePath, path.join(portableDir, exeName)); + } + + // 创建启动脚本 + const startScript = `@echo off +chcp 65001 >nul +title Pixiv Manager + +:: ======================================== +:: 代理配置 - 请根据你的代理软件修改端口号 +:: 常见端口: Clash=7890, V2Ray=10809, Shadowsocks=1080 +:: ======================================== +set PROXY_PORT=7890 + +echo. +echo ======================================== +echo Pixiv Manager Starting... +echo ======================================== +echo. + +cd /d "%~dp0" + +echo Current proxy port: %PROXY_PORT% +echo To change proxy port, edit this file and modify line 6 +echo. + +echo Starting backend server... +echo Access URL: http://localhost:3000 +echo. +echo Tip: Press Ctrl+C to stop server +echo. + +:: Start server and pass proxy port +pixiv-backend.exe --proxy-port=%PROXY_PORT% + +echo. +echo Server stopped +pause +`; + + await fs.writeFile(path.join(portableDir, 'start.bat'), startScript, 'utf8'); + + // 创建README + const readme = `# Pixiv Manager 便携版 + +## 使用说明 + +1. 双击 \`start.bat\` 启动程序 +2. 在浏览器中访问 http://localhost:3000 +3. 按 Ctrl+C 停止服务器 + +## 代理设置 + +如需使用代理,请编辑 \`start.bat\` 文件,修改第6行的端口号: +- Clash: 7890 +- V2Ray: 10809 +- Shadowsocks: 1080 + +## 注意事项 + +- 首次运行可能需要几秒钟启动时间 +- 程序会在当前目录创建数据文件夹 +- 支持Windows 10/11 64位系统 +`; + + await fs.writeFile(path.join(portableDir, 'README.txt'), readme, 'utf8'); + + // 创建数据目录 + await fs.ensureDir(path.join(portableDir, 'data')); + await fs.ensureDir(path.join(portableDir, 'downloads')); + + console.log('✅ 便携版创建完成!'); + console.log(`📁 位置: ${portableDir}`); + console.log('📦 可以将整个文件夹打包分发给用户'); + + } catch (error) { + console.error('❌ 创建便携版失败:', error); + } +} + +createPortable(); \ No newline at end of file