1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/cdn.ts b/src/util/cdn.ts
new file mode 100644
index 00000000..a66e2215
--- /dev/null
+++ b/src/util/cdn.ts
@@ -0,0 +1,24 @@
+import { Config } from "@fosscord/server-util";
+import FormData from "form-data";
+import fetch from "node-fetch";
+
+export async function uploadFile(path: string, file: Express.Multer.File) {
+ const form = new FormData();
+ form.append("file", file.buffer, {
+ contentType: file.mimetype,
+ filename: file.originalname
+ });
+
+ const response = await fetch(`${Config.get().cdn.endpoint || "http://localhost:3003"}${path}`, {
+ headers: {
+ signature: Config.get().security.requestSignature,
+ ...form.getHeaders()
+ },
+ method: "POST",
+ body: form
+ });
+ const result = await response.json();
+
+ if (response.status !== 200) throw result;
+ return result;
+}
|