summary refs log tree commit diff
path: root/src/cdn
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-02-17 18:10:05 -0500
committerPuyodead1 <puyodead@proton.me>2023-02-17 18:10:05 -0500
commit6fa4f9649ffee1f9909bc7645ca6d408d4699d4b (patch)
treead21c18a7f0f415e2cf1d429476ef576cbed1cb2 /src/cdn
parentImplement default avatars (diff)
downloadserver-6fa4f9649ffee1f9909bc7645ca6d408d4699d4b.tar.xz
async
Diffstat (limited to 'src/cdn')
-rw-r--r--src/cdn/routes/embed.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/cdn/routes/embed.ts b/src/cdn/routes/embed.ts
index 86268189..c38046ed 100644
--- a/src/cdn/routes/embed.ts
+++ b/src/cdn/routes/embed.ts
@@ -18,20 +18,20 @@
 
 import { Request, Response, Router } from "express";
 import FileType from "file-type";
-import fs from "fs";
+import fs from "fs/promises";
 import { HTTPError } from "lambert-server";
 import { join } from "path";
 
 const router = Router();
 
-function getFile(path: string) {
+async function getFile(path: string) {
 	try {
-		return fs.readFileSync(path);
+		return fs.readFile(path);
 	} catch (error) {
 		try {
-			const files = fs.readdirSync(path);
+			const files = await fs.readdir(path);
 			if (!files.length) return null;
-			return fs.readFileSync(join(path, files[0]));
+			return fs.readFile(join(path, files[0]));
 		} catch (error) {
 			return null;
 		}
@@ -43,7 +43,7 @@ router.get("/avatars/:id", async (req: Request, res: Response) => {
 	id = id.split(".")[0]; // remove .file extension
 	const path = join(process.cwd(), "assets", "default-avatars", `${id}.png`);
 
-	const file = getFile(path);
+	const file = await getFile(path);
 	if (!file) throw new HTTPError("not found", 404);
 	const type = await FileType.fromBuffer(file);