summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-27 20:01:50 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-27 20:01:50 +0200
commit4e69d834578c14215dbeef929813344a70c7ca72 (patch)
tree187eaf12ca04194c21f03ccb805ce66c2b4afbbb /src
parent:construction: attachment (diff)
downloadserver-4e69d834578c14215dbeef929813344a70c7ca72.tar.xz
:construction: file storage
Diffstat (limited to 'src')
-rw-r--r--src/index.ts2
-rw-r--r--src/util/FileStorage.ts10
-rw-r--r--src/util/Storage.ts4
3 files changed, 11 insertions, 5 deletions
diff --git a/src/index.ts b/src/index.ts

index cdf88fd9..72175f46 100644 --- a/src/index.ts +++ b/src/index.ts
@@ -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(() => { diff --git a/src/util/FileStorage.ts b/src/util/FileStorage.ts
index 01be0050..b4d00213 100644 --- a/src/util/FileStorage.ts +++ b/src/util/FileStorage.ts
@@ -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" }); + } } diff --git a/src/util/Storage.ts b/src/util/Storage.ts
index ad00fbb7..391afa83 100644 --- a/src/util/Storage.ts +++ b/src/util/Storage.ts
@@ -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;