summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Message.ts2
-rw-r--r--src/util/cdn.ts24
-rw-r--r--src/util/instanceOf.ts3
3 files changed, 26 insertions, 3 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; +} diff --git a/src/util/instanceOf.ts b/src/util/instanceOf.ts
index b67bde27..93a92805 100644 --- a/src/util/instanceOf.ts +++ b/src/util/instanceOf.ts
@@ -74,10 +74,9 @@ export function instanceOf( ): Boolean { if (!ref) ref = { obj: null, key: "" }; if (!path) path = "body"; + if (!type) return true; // no type was specified try { - if (!type) return true; // no type was specified - if (value == null) { if (optional) return true; throw new FieldError("BASE_TYPE_REQUIRED", req.t("common:field.BASE_TYPE_REQUIRED"));