fix: 修复不同环境挂载路径的问题

This commit is contained in:
chaos-zhu committed 2025-12-14 16:38:34 +08:00
1 parent a59e026c97
commit a0e23536ee
5 files changed
+8 -18

No files matched your search

+1 -1
View File
@@ -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
```
+1 -1
View File
@@ -6,7 +6,7 @@ services:
ports:
- "8092:3000"
volumes:
- ./data:/app/data
- ./db:/app/db
- ./uploads:/app/uploads
environment:
- NODE_ENV=production
+2 -7
View File
@@ -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)
}
+2 -2
View File
@@ -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 目录存在
+2 -7
View File
@@ -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,