Newer
Older
percord / cdn / src / util / Storage.ts
@Flam3rboy Flam3rboy on 3 Sep 2021 718 bytes :bug: fix #289
import { FileStorage } from "./FileStorage";
import path from "path";
import fse from "fs-extra";
process.cwd();

export interface Storage {
	set(path: string, data: Buffer): Promise<void>;
	get(path: string): Promise<Buffer | null>;
	delete(path: string): Promise<void>;
}

var storage: Storage;

if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
	var location = process.env.STORAGE_LOCATION;
	if (location) {
		location = path.resolve(location);
	} else {
		location = path.join(process.cwd(), "files");
	}
	console.log(`[CDN] storage location: ${location}`);
	fse.ensureDirSync(location);
	process.env.STORAGE_LOCATION = location;

	storage = new FileStorage();
}

export { storage };