summary refs log tree commit diff
path: root/cdn/src/util/Storage.ts
blob: 91f841a684db5ec71f6ecb664e33158cda4d3791 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { FileStorage } from "./FileStorage";
import path from "path";
import fse from "fs-extra";
import { bgCyan, black } from "nanocolors";
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: ${bgCyan(`${black(location)}`)}`);
	fse.ensureDirSync(location);
	process.env.STORAGE_LOCATION = location;

	storage = new FileStorage();
}

export { storage };