From 4e69d834578c14215dbeef929813344a70c7ca72 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 27 May 2021 20:01:50 +0200 Subject: [PATCH] :construction: file storage --- .env.example | 3 ++- package-lock.json | Bin 99841 -> 99841 bytes package.json | 2 +- src/index.ts | 2 +- src/util/FileStorage.ts | 10 ++++++++-- src/util/Storage.ts | 4 ++-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 2a1176ff..0a91585c 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -STORAGE_LOCATION=files/ \ No newline at end of file +STORAGE_LOCATION=files/ +PORT=3003 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9582bc4059efa90927b387b7d8a6a037902c144a..623e59c1a7b3a906401a8f3d6c9fe35fdec09e0f 100644 GIT binary patch delta 248 zcmZqdVQcJR+i;PI(P;A}rY#(kCx+@zF1X4*c@MV)qtWD#%<^FcA(4s2W^P3RhNe!2 z{)q-j*?y)afxdo){>fnxiI!O=ZXs?Z{uVCbo|f4K1>TuS+Gc)UC21l4{yxd&6{V$- zWyujn+9_e~W~n8H!4={9-pPjMfs-31)g7MpyZpM7%!kIfmn*}S>oX5$(FbPrc# delta 242 zcmZqdVQcJR+i;PI(Qxx6rY#(k8$I+V7hGkZyoXz2@~2?M(0uJ6v!ZY_125NPQ%g&8 z^K#FMqSU~!Voz6p$H?+@=fa$nB1iqQ>;mV!Bo}kv!jRN7e@pY6+ { 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; - get(hash: string, prefix?: string): Promise; + set(path: string, data: any): Promise; + get(path: string): Promise; } var storage: Storage;