From a0e23536ee8d6edbd12e1abb3d8e94c5187bfa8d Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Sun, 14 Dec 2025 16:38:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E6=8C=82=E8=BD=BD=E8=B7=AF=E5=BE=84=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docker-compose.yml | 2 +- server/plugins/scheduler.js | 9 ++------- server/utils/db.js | 4 ++-- server/utils/moderation.js | 9 ++------- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b67837a..4957a7d 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ docker compose up -d ### Docker run部署 ```bash -docker run -d --name easyimg -p 3000:3000 -v ./data:/app/data -v ./uploads:/app/uploads chaoszhu/easyimg +docker run -d --name easyimg -p 3000:3000 -v ./db:/app/db -v ./uploads:/app/uploads chaoszhu/easyimg ``` diff --git a/docker-compose.yml b/docker-compose.yml index 1b381ff..7d5afa3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: ports: - "8092:3000" volumes: - - ./data:/app/data + - ./db:/app/db - ./uploads:/app/uploads environment: - NODE_ENV=production diff --git a/server/plugins/scheduler.js b/server/plugins/scheduler.js index aa061cd..9563314 100644 --- a/server/plugins/scheduler.js +++ b/server/plugins/scheduler.js @@ -1,13 +1,8 @@ import db from '../utils/db.js' -import { join, dirname } from 'path' -import { fileURLToPath } from 'url' import { unlink } from 'fs/promises' import { existsSync } from 'fs' import { startProcessor as startModerationProcessor } from '../utils/moderationQueue.js' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) -const uploadsDir = join(__dirname, '../../uploads') +import { getUploadsDirPath, getImagePath } from '../utils/upload.js' // 硬删除已软删除的图片文件 export async function hardDeleteImages() { @@ -22,7 +17,7 @@ export async function hardDeleteImages() { for (const image of deletedImages) { try { // 删除物理文件 - const filePath = join(uploadsDir, image.filename) + const filePath = getImagePath(image.filename) if (existsSync(filePath)) { await unlink(filePath) } diff --git a/server/utils/db.js b/server/utils/db.js index b504f86..75db932 100644 --- a/server/utils/db.js +++ b/server/utils/db.js @@ -2,9 +2,9 @@ import Datastore from '@seald-io/nedb' import { join } from 'path' import { existsSync, mkdirSync } from 'fs' -// 数据目录:生产环境使用 /app/data,开发环境使用项目根目录下的 db +// 数据目录:生产环境使用 /app/db,开发环境使用项目根目录下的 db const dataDir = process.env.NODE_ENV === 'production' - ? '/app/data' + ? '/app/db' : join(process.cwd(), 'db') // 确保 db 目录存在 diff --git a/server/utils/moderation.js b/server/utils/moderation.js index 48e25a3..bd3604d 100644 --- a/server/utils/moderation.js +++ b/server/utils/moderation.js @@ -1,11 +1,6 @@ -import { join, dirname } from 'path' -import { fileURLToPath } from 'url' import { readFile } from 'fs/promises' import { existsSync } from 'fs' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) -const uploadsDir = join(__dirname, '../../uploads') +import { getImagePath } from './upload.js' /** * 内容审核服务 - 支持多厂商API适配 @@ -405,7 +400,7 @@ export async function moderateImage(imageId, filename, contentSafetyConfig) { } // 读取图片文件 - const filePath = join(uploadsDir, filename) + const filePath = getImagePath(filename) if (!existsSync(filePath)) { return { success: false,