feat: add storage path helpers
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
export async function ensureStorageDirs(config) {
|
||||
await fs.mkdir(path.join(config.storageDir, 'uploads'), { recursive: true });
|
||||
await fs.mkdir(path.join(config.storageDir, 'outputs'), { recursive: true });
|
||||
}
|
||||
|
||||
export function uploadPath(config, id, ext) {
|
||||
return path.join(config.storageDir, 'uploads', `${id}.${ext}`);
|
||||
}
|
||||
|
||||
export function outputPath(config, id, ext) {
|
||||
return path.join(config.storageDir, 'outputs', `${id}.${ext}`);
|
||||
}
|
||||
|
||||
export async function deleteIfExists(filePath) {
|
||||
try {
|
||||
await fs.unlink(filePath);
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user