summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 12:53:56 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 12:57:36 +1000
commitfa89b18d95f1639ec600716a2f715d2ab038c770 (patch)
tree6d62b82889dd71baaa9d064914ef61ea0318b484
parentVscode launch config (diff)
downloadserver-fa89b18d95f1639ec600716a2f715d2ab038c770.tar.xz
Rearrange assets a bit, fix anything that uses assets folder
-rw-r--r--assets/public/background.png (renamed from assets/background.png)bin319351 -> 319351 bytes
-rw-r--r--assets/public/checkLocale.js (renamed from assets/checkLocale.js)0
-rw-r--r--assets/public/dff87c953f43b561d71fbcfe8a93a79a.png (renamed from assets/dff87c953f43b561d71fbcfe8a93a79a.png)0
-rw-r--r--assets/public/endpoints.json (renamed from assets/endpoints.json)0
-rw-r--r--assets/public/features.json (renamed from assets/features.json)0
-rw-r--r--assets/public/fosscord-login.css (renamed from assets/fosscord-login.css)0
-rw-r--r--assets/public/fosscord.css (renamed from assets/fosscord.css)0
-rw-r--r--assets/public/openapi.json (renamed from assets/openapi.json)0
-rw-r--r--assets/public/schemas.json (renamed from assets/schemas.json)0
-rw-r--r--assets/public/user.css (renamed from assets/user.css)0
-rw-r--r--src/api/middlewares/TestClient.ts18
-rw-r--r--src/api/middlewares/Translation.ts8
-rw-r--r--src/api/routes/guilds/#guild_id/widget.png.ts2
13 files changed, 16 insertions, 12 deletions
diff --git a/assets/background.png b/assets/public/background.png
index 58369ab8..58369ab8 100644
--- a/assets/background.png
+++ b/assets/public/background.png
Binary files differdiff --git a/assets/checkLocale.js b/assets/public/checkLocale.js
index 016d66c8..016d66c8 100644
--- a/assets/checkLocale.js
+++ b/assets/public/checkLocale.js
diff --git a/assets/dff87c953f43b561d71fbcfe8a93a79a.png b/assets/public/dff87c953f43b561d71fbcfe8a93a79a.png
index e69de29b..e69de29b 100644
--- a/assets/dff87c953f43b561d71fbcfe8a93a79a.png
+++ b/assets/public/dff87c953f43b561d71fbcfe8a93a79a.png
diff --git a/assets/endpoints.json b/assets/public/endpoints.json
index 8b0514ce..8b0514ce 100644
--- a/assets/endpoints.json
+++ b/assets/public/endpoints.json
diff --git a/assets/features.json b/assets/public/features.json
index 05a858a0..05a858a0 100644
--- a/assets/features.json
+++ b/assets/public/features.json
diff --git a/assets/fosscord-login.css b/assets/public/fosscord-login.css
index ca0af064..ca0af064 100644
--- a/assets/fosscord-login.css
+++ b/assets/public/fosscord-login.css
diff --git a/assets/fosscord.css b/assets/public/fosscord.css
index 6078fdeb..6078fdeb 100644
--- a/assets/fosscord.css
+++ b/assets/public/fosscord.css
diff --git a/assets/openapi.json b/assets/public/openapi.json
index a8a657b2..a8a657b2 100644
--- a/assets/openapi.json
+++ b/assets/public/openapi.json
diff --git a/assets/schemas.json b/assets/public/schemas.json
index 24acc85f..24acc85f 100644
--- a/assets/schemas.json
+++ b/assets/public/schemas.json
diff --git a/assets/user.css b/assets/public/user.css
index a7e5c4f3..a7e5c4f3 100644
--- a/assets/user.css
+++ b/assets/public/user.css
diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts
index 0bd63eb5..765059c7 100644
--- a/src/api/middlewares/TestClient.ts
+++ b/src/api/middlewares/TestClient.ts
@@ -5,10 +5,12 @@ import fetch, { Response as FetchResponse } from "node-fetch";
 import ProxyAgent from 'proxy-agent';
 import { Config } from "@fosscord/util";
 
+const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "assets");
+
 export default function TestClient(app: Application) {
 	const agent = new ProxyAgent();
 	const assetCache = new Map<string, { response: FetchResponse; buffer: Buffer; }>();
-	const indexHTML = fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "client_test", "index.html"), { encoding: "utf8" });
+	const indexHTML = fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "index.html"), { encoding: "utf8" });
 
 	var html = indexHTML;
 	const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(
@@ -24,24 +26,24 @@ export default function TestClient(app: Application) {
 		html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`);
 	}
 	// inline plugins
-	var files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
+	var files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
 	var plugins = "";
-	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
+	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
 	html = html.replaceAll("<!-- preload plugin marker -->", plugins);
 
 	// plugins
-	files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "plugins"));
+	files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "plugins"));
 	plugins = "";
 	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; });
 	html = html.replaceAll("<!-- plugin marker -->", plugins);
 	//preload plugins
-	files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
+	files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
 	plugins = "";
-	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
+	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
 	html = html.replaceAll("<!-- preload plugin marker -->", plugins);
 
 
-	app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")));
+	app.use("/assets", express.static(path.join(ASSET_FOLDER_PATH, "public")));
 
 	app.get("/assets/:file", async (req: Request, res: Response) => {
 		delete req.headers.host;
@@ -90,7 +92,7 @@ export default function TestClient(app: Application) {
 
 		if (!useTestClient) return res.send("Test client is disabled on this instance. Use a stand-alone client to connect this instance.");
 
-		res.send(fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "developers.html"), { encoding: "utf8" }));
+		res.send(fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "developers.html"), { encoding: "utf8" }));
 	});
 	app.get("*", (req: Request, res: Response) => {
 		const { useTestClient } = Config.get().client;
diff --git a/src/api/middlewares/Translation.ts b/src/api/middlewares/Translation.ts
index 741d6baf..c0b7a4b8 100644
--- a/src/api/middlewares/Translation.ts
+++ b/src/api/middlewares/Translation.ts
@@ -5,9 +5,11 @@ import i18nextMiddleware from "i18next-http-middleware";
 import i18nextBackend from "i18next-node-fs-backend";
 import { Router } from "express";
 
+const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "assets");
+
 export async function initTranslation(router: Router) {
-	const languages = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales"));
-	const namespaces = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales", "en"));
+	const languages = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "locales"));
+	const namespaces = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "locales", "en"));
 	const ns = namespaces.filter((x) => x.endsWith(".json")).map((x) => x.slice(0, x.length - 5));
 
 	await i18next
@@ -19,7 +21,7 @@ export async function initTranslation(router: Router) {
 			fallbackLng: "en",
 			ns,
 			backend: {
-				loadPath: __dirname + "/../../locales/{{lng}}/{{ns}}.json"
+				loadPath:  path.join(ASSET_FOLDER_PATH, "locales") + "/{{lng}}/{{ns}}.json",
 			},
 			load: "all"
 		});
diff --git a/src/api/routes/guilds/#guild_id/widget.png.ts b/src/api/routes/guilds/#guild_id/widget.png.ts
index 721b59fb..c17d511e 100644
--- a/src/api/routes/guilds/#guild_id/widget.png.ts
+++ b/src/api/routes/guilds/#guild_id/widget.png.ts
@@ -34,7 +34,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	const sizeOf = require("image-size");
 
 	// TODO: Widget style templates need Fosscord branding
-	const source = path.join(__dirname, "..", "..", "..", "..", "assets", "widget", `${style}.png`);
+	const source = path.join(__dirname, "..", "..", "..", "..", "..", "assets", "widget", `${style}.png`);
 	if (!fs.existsSync(source)) {
 		throw new HTTPError("Widget template does not exist.", 400);
 	}