Add optional S3-based storage

This commit is contained in:
Yasindu20 2026-01-21 10:16:54 +05:30
parent 6c812b44bb
commit b93c840ee2
6 changed files with 135 additions and 46 deletions

View file

@ -0,0 +1,28 @@
import { IStorageAdapter } from "./index";
import { promises as fs } from "fs";
import path from "path";
export class LocalStorageAdapter implements IStorageAdapter {
baseDir: string;
constructor(baseDir: string) {
this.baseDir = baseDir;
}
async save(key: string, data: Buffer): Promise<string> {
const fullPath = path.join(this.baseDir, key);
await fs.mkdir(path.dirname(fullPath), { recursive: true });
await fs.writeFile(fullPath, data);
return key;
}
async get(key: string): Promise<Buffer> {
const fullPath = path.join(this.baseDir, key);
return fs.readFile(fullPath);
}
async delete(key: string): Promise<void> {
const fullPath = path.join(this.baseDir, key);
await fs.unlink(fullPath);
}
}