🚧 file storage
This commit is contained in:
parent
293894a4f9
commit
4e69d83457
@ -1 +1,2 @@
|
||||
STORAGE_LOCATION=files/
|
||||
STORAGE_LOCATION=files/
|
||||
PORT=3003
|
||||
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -37,7 +37,7 @@
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/btoa": "^1.2.3",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/express": "^4.17.12",
|
||||
"@types/multer": "^1.4.5",
|
||||
"@types/node": "^14.17.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
|
||||
@ -8,7 +8,7 @@ if (process.env.STORAGE_LOCATION) {
|
||||
}
|
||||
} else process.env.STORAGE_LOCATION = __dirname + "/../files/";
|
||||
|
||||
const server = new CDNServer();
|
||||
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
|
||||
server
|
||||
.start()
|
||||
.then(() => {
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
import { Storage } from "./Storage";
|
||||
import fs from "fs/promises";
|
||||
import { join } from "path";
|
||||
|
||||
export class FileStorage implements Storage {
|
||||
async get(path: string, prefix?: string) {}
|
||||
async get(path: string) {
|
||||
return fs.readFile(join(process.env.STORAGE_LOCATION || "", path), { encoding: "binary" });
|
||||
}
|
||||
|
||||
async set(path: string, value: any) {}
|
||||
async set(path: string, value: any) {
|
||||
return fs.writeFile(join(process.env.STORAGE_LOCATION || "", path), value, { encoding: "binary" });
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { FileStorage } from "./FileStorage";
|
||||
|
||||
export interface Storage {
|
||||
set(hash: string, data: any, prefix?: string): Promise<void>;
|
||||
get(hash: string, prefix?: string): Promise<any>;
|
||||
set(path: string, data: any): Promise<void>;
|
||||
get(path: string): Promise<any>;
|
||||
}
|
||||
|
||||
var storage: Storage;
|
||||
|
||||
Reference in New Issue
Block a user