diff --git a/src/lib/upload.ts b/src/lib/upload.ts index e589f6e..6a3ff62 100644 --- a/src/lib/upload.ts +++ b/src/lib/upload.ts @@ -3,6 +3,10 @@ import { existsSync } from 'fs'; import path from 'path'; import { nanoid } from 'nanoid'; +function getWorkingDirectory(): string { + return process.cwd(); +} + export interface UploadOptions { maxSize?: number; allowedTypes?: string[]; @@ -130,7 +134,7 @@ export async function uploadFile( const uploadBaseDir = process.env.UPLOAD_DIR || './uploads'; const datePath = getDatePath(); - const uploadDir = path.join(process.cwd(), uploadBaseDir, type, datePath); + const uploadDir = path.join(getWorkingDirectory(), uploadBaseDir, type, datePath); if (!existsSync(uploadDir)) { await mkdir(uploadDir, { recursive: true }); @@ -184,7 +188,7 @@ export async function getFileInfo(filePath: string) { createdAt: stats.birthtime, modifiedAt: stats.mtime, }; - } catch (error) { + } catch { return null; } }