From 7b84ef1aa027cf9a0defc90044012e625fe2e427 Mon Sep 17 00:00:00 2001 From: Joaquim Peixoto Date: Fri, 25 Jun 2021 20:20:00 +0100 Subject: FIX MKDIR --- src/util/FileStorage.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/util/FileStorage.ts b/src/util/FileStorage.ts index 9c9911f3..c6497306 100644 --- a/src/util/FileStorage.ts +++ b/src/util/FileStorage.ts @@ -4,27 +4,27 @@ import { join } from "path"; import "missing-native-js-functions"; export class FileStorage implements Storage { - async get(path: string): Promise { - path = join(process.env.STORAGE_LOCATION || "", path); - try { - const file = await fs.readFile(path); - // @ts-ignore - return file; - } catch (error) { - return null; - } - } + async get(path: string): Promise { + path = join(process.env.STORAGE_LOCATION || "", path); + try { + const file = await fs.readFile(path); + // @ts-ignore + return file; + } catch (error) { + return null; + } + } - async set(path: string, value: any) { - path = join(process.env.STORAGE_LOCATION || "", path); - const dir = path.split("/").slice(0, -1).join("/"); - await fs.mkdir(dir, { recursive: true }).caught(); + async set(path: string, value: any) { + path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); + const dir = path.split("/").slice(0, -1).join("/"); + await fs.mkdir(dir, { recursive: true }).caught(); - return fs.writeFile(path, value, { encoding: "binary" }); - } + return fs.writeFile(path, value, { encoding: "binary" }); + } - async delete(path: string) { - path = join(process.env.STORAGE_LOCATION || "", path); - await fs.unlink(path); - } + async delete(path: string) { + path = join(process.env.STORAGE_LOCATION || "", path); + await fs.unlink(path); + } } -- cgit 1.5.1 From 1a62f1dd8e77220bf86526349ae0ac54e0336464 Mon Sep 17 00:00:00 2001 From: Joaquim Peixoto Date: Fri, 25 Jun 2021 20:26:34 +0100 Subject: FIXS --- .env.example | 3 +++ src/util/FileStorage.ts | 42 +++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 .env.example (limited to 'src') diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..b5e011f1 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +STORAGE_LOCATION=files/ +STORAGE_PROVIDER=file +PORT=3003 \ No newline at end of file diff --git a/src/util/FileStorage.ts b/src/util/FileStorage.ts index c6497306..42b32528 100644 --- a/src/util/FileStorage.ts +++ b/src/util/FileStorage.ts @@ -4,27 +4,27 @@ import { join } from "path"; import "missing-native-js-functions"; export class FileStorage implements Storage { - async get(path: string): Promise { - path = join(process.env.STORAGE_LOCATION || "", path); - try { - const file = await fs.readFile(path); - // @ts-ignore - return file; - } catch (error) { - return null; - } - } + async get(path: string): Promise { + path = join(process.env.STORAGE_LOCATION || "", path); + try { + const file = await fs.readFile(path); + // @ts-ignore + return file; + } catch (error) { + return null; + } + } - async set(path: string, value: any) { - path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); - const dir = path.split("/").slice(0, -1).join("/"); - await fs.mkdir(dir, { recursive: true }).caught(); + async set(path: string, value: any) { + path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); + const dir = path.split("/").slice(0, -1).join("/"); + await fs.mkdir(dir, { recursive: true }).caught(); - return fs.writeFile(path, value, { encoding: "binary" }); - } + return fs.writeFile(path, value, { encoding: "binary" }); + } - async delete(path: string) { - path = join(process.env.STORAGE_LOCATION || "", path); - await fs.unlink(path); - } -} + async delete(path: string) { + path = join(process.env.STORAGE_LOCATION || "", path); + await fs.unlink(path); + } +} \ No newline at end of file -- cgit 1.5.1 From b874e999ab0a7d3d0954d3a32e8593c5dab63895 Mon Sep 17 00:00:00 2001 From: Joaquim Peixoto Date: Fri, 25 Jun 2021 20:28:59 +0100 Subject: 4 TABS --- src/util/FileStorage.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/util/FileStorage.ts b/src/util/FileStorage.ts index 42b32528..48b4a6a5 100644 --- a/src/util/FileStorage.ts +++ b/src/util/FileStorage.ts @@ -17,14 +17,14 @@ export class FileStorage implements Storage { async set(path: string, value: any) { path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/"); - const dir = path.split("/").slice(0, -1).join("/"); - await fs.mkdir(dir, { recursive: true }).caught(); + const dir = path.split("/").slice(0, -1).join("/"); + await fs.mkdir(dir, { recursive: true }).caught(); - return fs.writeFile(path, value, { encoding: "binary" }); + return fs.writeFile(path, value, { encoding: "binary" }); } async delete(path: string) { path = join(process.env.STORAGE_LOCATION || "", path); await fs.unlink(path); } -} \ No newline at end of file +} -- cgit 1.5.1