summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 17:25:26 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 17:25:26 +0200
commit7e5c51652bc7188b0d7ddd58dda3afa5856d5fce (patch)
tree2b020354ba73d79511cba905903f9add18826d3e /util
parent:art: cdn now also works without setting a public endpoint (diff)
downloadserver-7e5c51652bc7188b0d7ddd58dda3afa5856d5fce.tar.xz
:sparkles: handleFile() now returns mime_type and size
Diffstat (limited to 'util')
-rw-r--r--util/src/util/cdn.ts23
1 files changed, 19 insertions, 4 deletions
diff --git a/util/src/util/cdn.ts b/util/src/util/cdn.ts
index 2de23f5d..8d45f85f 100644
--- a/util/src/util/cdn.ts
+++ b/util/src/util/cdn.ts
@@ -25,15 +25,30 @@ export async function uploadFile(path: string, file: Express.Multer.File) {
 	return result;
 }
 
-export async function handleFile(path: string, body?: string): Promise<string | undefined> {
-	if (!body || !body.startsWith("data:")) return body;
+export async function handleFile(
+	path: string,
+	body?: string
+): Promise<
+	| (string & {
+			id: string;
+			content_type: string;
+			size: number;
+			url: string;
+	  })
+	| undefined
+> {
+	if (!body || !body.startsWith("data:")) return undefined;
 	try {
 		const mimetype = body.split(":")[1].split(";")[0];
 		const buffer = Buffer.from(body.split(",")[1], "base64");
 
 		// @ts-ignore
-		const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" });
-		return id;
+		const file = await uploadFile(path, { buffer, mimetype, originalname: "banner" });
+		const obj = file.id;
+		for (const key in file) {
+			obj[key] = file[key];
+		}
+		return obj;
 	} catch (error) {
 		console.error(error);
 		throw new HTTPError("Invalid " + path);