Files
nanodrop/src/services/storage.ts
Brendan Chen 157d1e8230 Add auth service, storage service, types, and logging middleware
- Auth service: hashPassword/verifyPassword via bcrypt
- Storage service: saveFile, getFilePath, deleteStoredFile with ENOENT handling
- Types: JwtPayload interface
- Logging middleware: createLogger writing AUTH_FAILURE, AUTH_SUCCESS, FILE_NOT_FOUND
- 27 tests passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 15:49:22 -08:00

22 lines
644 B
TypeScript

import { writeFile, unlink } from 'fs/promises';
import { join } from 'path';
export async function saveFile(uploadDir: string, storedName: string, data: Buffer): Promise<string> {
await writeFile(join(uploadDir, storedName), data);
return storedName;
}
export function getFilePath(uploadDir: string, storedName: string): string {
return join(uploadDir, storedName);
}
export async function deleteStoredFile(uploadDir: string, storedName: string): Promise<void> {
try {
await unlink(join(uploadDir, storedName));
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
throw err;
}
}
}