更新 构建说明

This commit is contained in:
Chen committed 2025-12-05 20:11:34 +08:00
1 parent 80349d54b5
commit 395b469d96
9 files changed
+109 -17

No files matched your search

+2 -2
View File
@@ -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",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "flypic-backend",
"version": "1.0.5",
"version": "1.0.0",
"description": "FlyPic backend server",
"main": "server.js",
"scripts": {
+2 -2
View File
@@ -5,8 +5,8 @@
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FlyPic 飞图 - 图片素材库管理</title>
<script type="module" crossorigin src="/assets/index-B4Eh5nez.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BV-u5Ri4.css">
<script type="module" crossorigin src="/assets/index-DHmcK1E-.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-KC1uux7K.css">
</head>
<body>
<div id="root"></div>␍
+15 -2
View File
@@ -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) {
+13 -1
View File
@@ -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;
@@ -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
};
}
/**
* 获取素材库统计信息
*/
+8 -2
View File
@@ -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);
+5 -3
View File
@@ -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
+21 -1
View File
@@ -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