✨ message attachments

This commit is contained in:
Flam3rboy
2021-05-30 01:44:09 +02:00
parent b59d32f9bb
commit d61bbe8293
7 changed files with 80 additions and 46 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ export async function handleMessage(opts: Partial<Message>) {
mention_channels_ids: [],
mention_role_ids: [],
mention_user_ids: [],
attachments: [], // TODO: message attachments
attachments: opts.attachments || [], // TODO: message attachments
embeds: opts.embeds || [],
reactions: opts.reactions || [],
type: opts.type ?? 0
+24
View File
@@ -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;
}