1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-22 02:31:36 +02:00
This commit is contained in:
Joaquim Peixoto 2021-06-25 20:26:34 +01:00
parent 7b84ef1aa0
commit 1a62f1dd8e
2 changed files with 24 additions and 21 deletions

3
.env.example Normal file
View File

@ -0,0 +1,3 @@
STORAGE_LOCATION=files/
STORAGE_PROVIDER=file
PORT=3003

View File

@ -4,27 +4,27 @@ import { join } from "path";
import "missing-native-js-functions";
export class FileStorage implements Storage {
async get(path: string): Promise<Buffer | null> {
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<Buffer | null> {
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);
}
}