From d61bbe82936cffe60375436952218775ec1c4506 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 30 May 2021 01:44:09 +0200 Subject: :sparkles: message attachments --- src/util/cdn.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/util/cdn.ts (limited to 'src/util/cdn.ts') 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; +} -- cgit 1.5.1