import { Injectable } from '@nestjs/common';
import * as fs from 'fs/promises';
import * as path from 'path';
@Injectable()
export class LocalStorageService {
private readonly basePath = '/var/glamora/uploads';
async save(buffer: Buffer, directory: string, filename: string): Promise<string> {
const dirPath = path.join(this.basePath, directory);
await fs.mkdir(dirPath, { recursive: true });
const filePath = path.join(dirPath, filename);
await fs.writeFile(filePath, buffer);
return filePath;
}
async delete(filePath: string): Promise<void> {
try { await fs.unlink(filePath); } catch {}
}
async exists(filePath: string): Promise<boolean> {
try { await fs.access(filePath); return true; } catch { return false; }
}
}