summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 16:50:22 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 16:50:53 +1100
commit0f9951bb0e70f9e6e2c4fdfc2bc51b6f93cd429e (patch)
tree5c8d885fee000006cb0238e5eb013f0cff323b27 /src
parentChange android and ios client downloads to use /download endpoint, update Rel... (diff)
downloadserver-0f9951bb0e70f9e6e2c4fdfc2bc51b6f93cd429e.tar.xz
TestClient middleware will now add cache misses to file for generate:client script to fetch. Also patch discord icon top left
Diffstat (limited to 'src')
-rw-r--r--src/api/middlewares/TestClient.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts
index 62128b36..ad759fdb 100644
--- a/src/api/middlewares/TestClient.ts
+++ b/src/api/middlewares/TestClient.ts
@@ -13,7 +13,7 @@ export default function TestClient(app: Application) {
 	const agent = new ProxyAgent();
 	const assetCache = new Map<
 		string,
-		{ response: FetchResponse; buffer: Buffer }
+		{ response: FetchResponse; buffer: Buffer; }
 	>();
 	const indexHTML = fs.readFileSync(
 		path.join(ASSET_FOLDER_PATH, "client_test", "index.html"),
@@ -76,13 +76,7 @@ export default function TestClient(app: Application) {
 	app.use("/assets", express.static(path.join(ASSET_FOLDER_PATH, "cache")));
 
 	app.get("/assets/:file", async (req: Request, res: Response) => {
-		if (!hasWarnedAboutCache) {
-			hasWarnedAboutCache = true;
-			if (req.params.file.includes(".js"))
-				console.warn(
-					`[TestClient] Cache miss for file ${req.params.file}! Use 'npm run generate:client' to cache and patch.`,
-				);
-		}
+		if (req.params.file.includes(".map")) return res.status(404);
 
 		delete req.headers.host;
 		var response: FetchResponse;
@@ -124,6 +118,16 @@ export default function TestClient(app: Application) {
 		});
 		assetCache.set(req.params.file, { buffer, response });
 
+		if (response.status == 200) {
+			// if (!hasWarnedAboutCache) {
+			hasWarnedAboutCache = true;
+			console.warn(
+				`[TestClient] Cache miss for file ${req.params.file}! Use 'npm run generate:client' to cache and patch.`,
+			);
+			await fs.promises.appendFile(path.join(ASSET_FOLDER_PATH, "cacheMisses"), req.params.file + "\n");
+			// }
+		}
+
 		return res.send(buffer);
 	});
 	app.get("/developers*", (req: Request, res: Response) => {