fix: fileStorage path issues between local and staging environments

- Store relative paths in database instead of absolute paths
- Reconstruct absolute paths at runtime using UPLOAD_DIR env var
- Add VOLUME for /app/uploads in Dockerfile for persistent storage
- Create uploads directory with proper permissions in Docker
- Add error handling for missing UPLOAD_DIR in findUniq.ts
- Simplify GitHub workflow memory in QWEN.md (manual handling)

This fixes the 500 errors on staging for file create/delete operations
caused by environment-specific absolute paths stored in database.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-04-14 10:57:51 +08:00
parent 11ff5f5c01
commit de4563c914
5 changed files with 20 additions and 42 deletions

View File

@@ -79,7 +79,7 @@ const fileStorageCreate = async (context: Context) => {
data: {
name: finalName,
realName: file.name,
path: rootPath,
path: pathName, // Store relative path (e.g., "images", "audio", "documents")
mimeType: finalMimeType,
category,
link: `/api/fileStorage/findUnique/${finalName}`,

View File

@@ -36,7 +36,7 @@ const fileStorageDelete = async (context: Context) => {
};
}
const filePath = path.join(file.path, file.name);
const filePath = path.join(UPLOAD_DIR, file.path, file.name);
try {
// Hapus file dari filesystem

View File

@@ -3,6 +3,8 @@ import { Context } from "elysia";
import fs from "fs/promises";
import path from "path";
const UPLOAD_DIR = process.env.WIBU_UPLOAD_DIR;
const fileStorageFindUnique = async (context: Context) => {
const { name } = context.params;
@@ -20,9 +22,17 @@ const fileStorageFindUnique = async (context: Context) => {
};
}
if (!UPLOAD_DIR) {
context.set.status = "Internal Server Error";
return {
status: 500,
message: "UPLOAD_DIR is not defined",
};
}
console.log(data);
const file = await fs.readFile(path.join(data.path, data.name));
const file = await fs.readFile(path.join(UPLOAD_DIR, data.path, data.name));
context.set.headers = {
"Content-Type": data.mimeType,
"Content-Length": file.length,