diff --git a/util/src/util/cdn.ts b/util/src/util/cdn.ts
index 8d45f85f..ea950cd1 100644
--- a/util/src/util/cdn.ts
+++ b/util/src/util/cdn.ts
@@ -4,7 +4,9 @@ import fetch from "node-fetch";
import { Config } from "./Config";
import multer from "multer";
-export async function uploadFile(path: string, file: Express.Multer.File) {
+export async function uploadFile(path: string, file?: Express.Multer.File) {
+ if (!file?.buffer) throw new HTTPError("Missing file in body");
+
const form = new FormData();
form.append("file", file.buffer, {
contentType: file.mimetype,
@@ -25,30 +27,15 @@ export async function uploadFile(path: string, file: Express.Multer.File) {
return result;
}
-export async function handleFile(
- path: string,
- body?: string
-): Promise<
- | (string & {
- id: string;
- content_type: string;
- size: number;
- url: string;
- })
- | undefined
-> {
+export async function handleFile(path: string, body?: string): Promise<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 file = await uploadFile(path, { buffer, mimetype, originalname: "banner" });
- const obj = file.id;
- for (const key in file) {
- obj[key] = file[key];
- }
- return obj;
+ const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" });
+ return id;
} catch (error) {
console.error(error);
throw new HTTPError("Invalid " + path);
|