import * as fs from "node:fs";
import * as Path from "node:path";
import config from "../../config/index.js";
export class InternalStorage {
    static resolvePath = (key)=>Path.resolve(config.mediaDir, key);
    static read(key) {
        return fs.createReadStream(InternalStorage.resolvePath(key));
    }
    static saveFromPath(key, srcPath) {
        fs.mkdirSync(config.mediaDir, {
            recursive: true
        });
        fs.copyFileSync(srcPath, InternalStorage.resolvePath(key));
        return `${config.url}/files/${key}`;
    }
    static saveFromBuffer(key, data) {
        fs.mkdirSync(config.mediaDir, {
            recursive: true
        });
        fs.writeFileSync(InternalStorage.resolvePath(key), data);
        return `${config.url}/files/${key}`;
    }
    static del(key) {
        fs.unlink(InternalStorage.resolvePath(key), ()=>{});
    }
}
