summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.env.example3
-rw-r--r--package-lock.json14
-rw-r--r--package.json2
-rw-r--r--src/index.ts2
-rw-r--r--src/util/FileStorage.ts10
-rw-r--r--src/util/Storage.ts4
6 files changed, 21 insertions, 14 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 9582bc40..623e59c1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -26,7 +26,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",
@@ -90,9 +90,9 @@
 			}
 		},
 		"node_modules/@types/express": {
-			"version": "4.17.11",
-			"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
-			"integrity": "sha512-no+R6rW60JEc59977wIxreQVsIEOAYwgCqldrA/vkpCnbD7MqTefO97lmoBe4WE0F156bC4uLSP1XHDOySnChg==",
+			"version": "4.17.12",
+			"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
+			"integrity": "sha512-pTYas6FrP15B1Oa0bkN5tQMNqOcVXa9j4FTFtO8DWI9kppKib+6NJtfTOOLcwxuuYvcX2+dVG6et1SxW/Kc17Q==",
 			"dev": true,
 			"dependencies": {
 				"@types/body-parser": "*",
@@ -1585,9 +1585,9 @@
 			}
 		},
 		"@types/express": {
-			"version": "4.17.11",
-			"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
-			"integrity": "sha512-no+R6rW60JEc59977wIxreQVsIEOAYwgCqldrA/vkpCnbD7MqTefO97lmoBe4WE0F156bC4uLSP1XHDOySnChg==",
+			"version": "4.17.12",
+			"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz",
+			"integrity": "sha512-pTYas6FrP15B1Oa0bkN5tQMNqOcVXa9j4FTFtO8DWI9kppKib+6NJtfTOOLcwxuuYvcX2+dVG6et1SxW/Kc17Q==",
 			"dev": true,
 			"requires": {
 				"@types/body-parser": "*",
diff --git a/package.json b/package.json
index 69707a51..35599d84 100644
--- a/package.json
+++ b/package.json
@@ -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",
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;