summary refs log tree commit diff
path: root/cdn/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-03 04:02:21 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-03 04:02:21 +0200
commit4fe30d32c04db2b134c779659607109e764549ee (patch)
tree6aad23acbde6ee27b86aabae085d0eedca13a4c1 /cdn/src
parent:arrow_up: update dependencies (diff)
downloadserver-4fe30d32c04db2b134c779659607109e764549ee.tar.xz
:bug: fix #289
Diffstat (limited to 'cdn/src')
-rw-r--r--cdn/src/start.ts15
-rw-r--r--cdn/src/util/Storage.ts15
2 files changed, 14 insertions, 16 deletions
diff --git a/cdn/src/start.ts b/cdn/src/start.ts
index 2a449130..71681b40 100644
--- a/cdn/src/start.ts
+++ b/cdn/src/start.ts
@@ -1,21 +1,6 @@
-import path from "path";
 import dotenv from "dotenv";
-import fse from "fs-extra";
 dotenv.config();
 
-if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
-// TODO:nodejs path.join trailing slash windows compatible
-if (process.env.STORAGE_PROVIDER === "file") {
-	if (process.env.STORAGE_LOCATION) {
-		if (!process.env.STORAGE_LOCATION.startsWith("/")) {
-			process.env.STORAGE_LOCATION = path.join(__dirname, "..", process.env.STORAGE_LOCATION, "/");
-		}
-	} else {
-		process.env.STORAGE_LOCATION = path.join(__dirname, "..", "files", "/");
-	}
-	fse.ensureDirSync(process.env.STORAGE_LOCATION);
-}
-
 import { CDNServer } from "./Server";
 const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
 server
diff --git a/cdn/src/util/Storage.ts b/cdn/src/util/Storage.ts
index f8b09e71..5cf1eb80 100644
--- a/cdn/src/util/Storage.ts
+++ b/cdn/src/util/Storage.ts
@@ -1,4 +1,7 @@
 import { FileStorage } from "./FileStorage";
+import path from "path";
+import fse from "fs-extra";
+process.cwd();
 
 export interface Storage {
 	set(path: string, data: Buffer): Promise<void>;
@@ -8,7 +11,17 @@ export interface Storage {
 
 var storage: Storage;
 
-if (process.env.STORAGE_PROVIDER === "file") {
+if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
+	var location = process.env.STORAGE_LOCATION;
+	if (location) {
+		location = path.resolve(location);
+	} else {
+		location = path.join(process.cwd(), "files");
+	}
+	console.log(`[CDN] storage location: ${location}`);
+	fse.ensureDirSync(location);
+	process.env.STORAGE_LOCATION = location;
+
 	storage = new FileStorage();
 }