summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-30 01:44:09 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-30 01:44:09 +0200
commitd61bbe82936cffe60375436952218775ec1c4506 (patch)
tree939e4f9bace2557bbf274b4ebb10ec18d1446058 /src/util
parent:zap: improve asset caching (diff)
downloadserver-d61bbe82936cffe60375436952218775ec1c4506.tar.xz
:sparkles: message attachments
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Message.ts2
-rw-r--r--src/util/cdn.ts24
2 files changed, 25 insertions, 1 deletions
diff --git a/src/util/Message.ts b/src/util/Message.ts

index 27796997..9b928031 100644 --- a/src/util/Message.ts +++ b/src/util/Message.ts
@@ -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 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; +}