From 395b469d96695c737496bd8ebd7302f1a22eaf8f Mon Sep 17 00:00:00 2001 From: Chen Date: Fri, 5 Dec 2025 20:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flypic/app/server/package-lock.json | 4 +- flypic/app/server/package.json | 2 +- flypic/app/server/public/index.html | 4 +- flypic/app/server/server.js | 17 ++++++- flypic/app/server/src/routes/library.js | 14 +++++- .../app/server/src/services/LibraryService.js | 45 +++++++++++++++++-- flypic/app/server/utils/config.js | 10 ++++- flypic/manifest | 8 ++-- scripts/build.js | 22 ++++++++- 9 files changed, 109 insertions(+), 17 deletions(-) diff --git a/flypic/app/server/package-lock.json b/flypic/app/server/package-lock.json index bb48846..efce4da 100644 --- a/flypic/app/server/package-lock.json +++ b/flypic/app/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "flypic-backend", - "version": "1.0.5", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "flypic-backend", - "version": "1.0.5", + "version": "1.0.0", "dependencies": { "better-sqlite3": "^9.2.2", "chokidar": "^3.6.0", diff --git a/flypic/app/server/package.json b/flypic/app/server/package.json index 8775514..602765a 100644 --- a/flypic/app/server/package.json +++ b/flypic/app/server/package.json @@ -1,6 +1,6 @@ { "name": "flypic-backend", - "version": "1.0.5", + "version": "1.0.0", "description": "FlyPic backend server", "main": "server.js", "scripts": { diff --git a/flypic/app/server/public/index.html b/flypic/app/server/public/index.html index eefa7a5..32b8bb1 100644 --- a/flypic/app/server/public/index.html +++ b/flypic/app/server/public/index.html @@ -5,8 +5,8 @@ FlyPic 飞图 - 图片素材库管理 - - + +
diff --git a/flypic/app/server/server.js b/flypic/app/server/server.js index 8e6e1cd..f9034de 100644 --- a/flypic/app/server/server.js +++ b/flypic/app/server/server.js @@ -173,11 +173,24 @@ server.listen(PORT, () => { } } - // 为当前素材库启动文件监控 + // 为当前素材库启动文件监控(仅当索引存在时) if (currentConfig.currentLibraryId) { const currentLib = currentConfig.libraries.find(lib => lib.id === currentConfig.currentLibraryId); if (currentLib) { - lightweightWatcher.watch(currentLib.id, currentLib.path, currentLib.name, io); + const fs = require('fs'); + const { getFlypicPath, getDatabasePath } = require('./src/config'); + const flypicPath = getFlypicPath(currentLib.path); + const dbPath = getDatabasePath(currentLib.path); + + // 只有当文件夹和索引都存在时才启动监控 + const folderExists = fs.existsSync(currentLib.path); + const indexExists = fs.existsSync(flypicPath) && fs.existsSync(dbPath); + + if (folderExists && indexExists) { + lightweightWatcher.watch(currentLib.id, currentLib.path, currentLib.name, io); + } else { + console.log(`⚠️ 跳过文件监控: ${currentLib.name} (${!folderExists ? '文件夹不存在' : '索引不存在'})`); + } } } } catch (e) { diff --git a/flypic/app/server/src/routes/library.js b/flypic/app/server/src/routes/library.js index 6919901..0faaae0 100644 --- a/flypic/app/server/src/routes/library.js +++ b/flypic/app/server/src/routes/library.js @@ -79,10 +79,12 @@ router.put('/:id', asyncHandler(async (req, res) => { /** * 删除素材库 * DELETE /api/library/:id + * Query: autoSelectNext - 是否自动选择下一个素材库,默认 true */ router.delete('/:id', asyncHandler(async (req, res) => { const { id } = req.params; - const result = await libraryService.deleteLibrary(id); + const autoSelectNext = req.query.autoSelectNext !== 'false'; + const result = await libraryService.deleteLibrary(id, autoSelectNext); res.json({ success: true, data: result }); })); @@ -106,4 +108,14 @@ router.get('/:id/stats', asyncHandler(async (req, res) => { res.json({ success: true, data: result }); })); +/** + * 验证素材库路径是否存在 + * GET /api/library/:id/validate + */ +router.get('/:id/validate', asyncHandler(async (req, res) => { + const { id } = req.params; + const result = libraryService.validateLibraryPath(id); + res.json({ success: true, data: result }); +})); + module.exports = router; diff --git a/flypic/app/server/src/services/LibraryService.js b/flypic/app/server/src/services/LibraryService.js index 06097f2..dfc8bfa 100644 --- a/flypic/app/server/src/services/LibraryService.js +++ b/flypic/app/server/src/services/LibraryService.js @@ -6,7 +6,7 @@ const fs = require('fs'); const path = require('path'); const { NotFoundError, ValidationError } = require('../middleware/errorHandler'); -const { getFlypicPath, getDatabasePath } = require('../config'); +const { getFlypicPath, getDatabasePath, getThumbnailsPath } = require('../config'); class LibraryService { constructor(configManager, dbPool, scanManager, lightweightWatcher, io) { @@ -126,8 +126,10 @@ class LibraryService { /** * 删除素材库 + * @param {string} id - 素材库ID + * @param {boolean} autoSelectNext - 是否自动选择下一个素材库,默认 true */ - async deleteLibrary(id) { + async deleteLibrary(id, autoSelectNext = true) { const config = this.configManager.load(); const library = config.libraries.find(lib => lib.id === id); @@ -139,7 +141,7 @@ class LibraryService { await this._cleanupLibraryResources(id, library.path); // 删除配置 - this.configManager.removeLibrary(id); + this.configManager.removeLibrary(id, autoSelectNext); return { success: true, @@ -239,6 +241,43 @@ class LibraryService { await new Promise(resolve => setTimeout(resolve, 300)); } + /** + * 验证素材库路径是否存在 + * 返回三种状态: + * - status: 'ok' - 素材库正常(文件夹和索引都存在) + * - status: 'missing_index' - 文件夹存在但索引不存在(需要重新扫描) + * - status: 'missing_folder' - 文件夹不存在(需要打开其他或新建) + */ + validateLibraryPath(libraryId) { + const config = this.configManager.load(); + const library = config.libraries.find(lib => lib.id === libraryId); + + if (!library) { + throw new NotFoundError('Library', libraryId); + } + + const folderExists = fs.existsSync(library.path); + const flypicPath = getFlypicPath(library.path); + const dbPath = getDatabasePath(library.path); + const indexExists = fs.existsSync(flypicPath) && fs.existsSync(dbPath); + + let status = 'ok'; + if (!folderExists) { + status = 'missing_folder'; + } else if (!indexExists) { + status = 'missing_index'; + } + + return { + libraryId, + path: library.path, + name: library.name, + folderExists, + indexExists, + status + }; + } + /** * 获取素材库统计信息 */ diff --git a/flypic/app/server/utils/config.js b/flypic/app/server/utils/config.js index e4fa34c..1aeff6b 100644 --- a/flypic/app/server/utils/config.js +++ b/flypic/app/server/utils/config.js @@ -149,13 +149,19 @@ function addLibrary(name, libraryPath) { /** * Remove library from config + * @param {string} libraryId - 要删除的素材库ID + * @param {boolean} autoSelectNext - 是否自动选择下一个素材库,默认 true */ -function removeLibrary(libraryId) { +function removeLibrary(libraryId, autoSelectNext = true) { const config = loadConfig(); config.libraries = config.libraries.filter(lib => lib.id !== libraryId); if (config.currentLibraryId === libraryId) { - config.currentLibraryId = config.libraries.length > 0 ? config.libraries[0].id : null; + if (autoSelectNext) { + config.currentLibraryId = config.libraries.length > 0 ? config.libraries[0].id : null; + } else { + config.currentLibraryId = null; + } } saveConfig(config); diff --git a/flypic/manifest b/flypic/manifest index 0bb1c3c..3ccb7bc 100644 --- a/flypic/manifest +++ b/flypic/manifest @@ -3,10 +3,12 @@ version=1.0.5 desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用,支持数十万级别图片流畅浏览,非侵入式设计,100% 开源免费 arch=x86_64 display_name=FlyPic -maintainer=ZangXincz -distributor=ZangXincz +maintainer=FlyPic +maintainer_url=https://flypic.shikejk.com/ +distributor=ZangXin +distributor_url=https://github.com/ZangXincz desktop_uidir=ui desktop_applaunchname=flypic.Application source=thirdparty service_port=15002 -install_dep_apps=nodejs_v22 +install_dep_apps=nodejs_v22 \ No newline at end of file diff --git a/scripts/build.js b/scripts/build.js index f430be3..70cb10b 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -101,12 +101,32 @@ console.log(' ⏳ 首次构建需要编译原生模块,约需 1-3 分钟...\ const dockerPath = toDockerPath(packServerDir); -// 创建临时安装脚本 +// 创建临时安装脚本(使用国内镜像源) const installScript = `#!/bin/sh set -e + +# 使用阿里云镜像源加速(避免连接超时) +# 兼容新旧版本的 Debian 配置 +if [ -f /etc/apt/sources.list ]; then + sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list + sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list +fi + +if [ -d /etc/apt/sources.list.d ]; then + find /etc/apt/sources.list.d -name "*.sources" -exec sed -i 's/deb.debian.org/mirrors.aliyun.com/g; s/security.debian.org/mirrors.aliyun.com/g' {} \\; +fi + apt-get update apt-get install -y python3 make g++ --no-install-recommends + +# 配置 npm 使用国内镜像 npm config set registry https://registry.npmmirror.com + +# 使用环境变量配置二进制文件镜像源(避免网络超时) +export NODEJS_ORG_MIRROR=https://registry.npmmirror.com/-/binary/node/ +export SHARP_DIST_BASE_URL=https://registry.npmmirror.com/-/binary/sharp/ +export BETTER_SQLITE3_BINARY_HOST=https://registry.npmmirror.com/-/binary/better-sqlite3/ + rm -rf node_modules package-lock.json npm install --production echo