24 lines
669 B
JavaScript
24 lines
669 B
JavaScript
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;
|
|
}
|
|
}
|