mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(rest/request_manager): support for multiple attachments (#484)
* feat(rest/request_manager): support for multiple attachments Closes #483 * Use .map() instead of forEach()
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
import { authorization, eventHandlers } from "../bot.ts";
|
import { authorization, eventHandlers } from "../bot.ts";
|
||||||
import { Errors, HttpResponseCode, RequestMethods } from "../types/mod.ts";
|
import {
|
||||||
|
Errors,
|
||||||
|
FileContent,
|
||||||
|
HttpResponseCode,
|
||||||
|
RequestMethods,
|
||||||
|
} from "../types/mod.ts";
|
||||||
import {
|
import {
|
||||||
API_VERSION,
|
API_VERSION,
|
||||||
BASE_URL,
|
BASE_URL,
|
||||||
@@ -155,8 +160,16 @@ function createRequestBody(body: any, method: RequestMethods) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body?.file) {
|
if (body?.file) {
|
||||||
|
if (!Array.isArray(body.file)) body.file = [body.file];
|
||||||
|
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append("file", body.file.blob, body.file.name);
|
// form.append("file", body.file.blob, body.file.name);
|
||||||
|
|
||||||
|
body.file.map((file: FileContent, index: number) =>
|
||||||
|
// The key of the form data item must be unique; otherwise, Discordeno only considers the first item in the form data with the same names.
|
||||||
|
form.append(`file${index + 1}`, file.blob, file.name)
|
||||||
|
);
|
||||||
|
|
||||||
form.append("payload_json", JSON.stringify({ ...body, file: undefined }));
|
form.append("payload_json", JSON.stringify({ ...body, file: undefined }));
|
||||||
body.file = form;
|
body.file = form;
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export interface MessageContent {
|
|||||||
/** Whether this is a TextToSpeech message */
|
/** Whether this is a TextToSpeech message */
|
||||||
tts?: boolean;
|
tts?: boolean;
|
||||||
/** The contents of the file being sent */
|
/** The contents of the file being sent */
|
||||||
file?: { blob: unknown; name: string };
|
file?: FileContent | FileContent[];
|
||||||
/** Embed object */
|
/** Embed object */
|
||||||
embed?: Embed;
|
embed?: Embed;
|
||||||
/** JSON encoded body of any additional request fields. */
|
/** JSON encoded body of any additional request fields. */
|
||||||
@@ -120,6 +120,11 @@ export interface MessageContent {
|
|||||||
replyMessageID?: string;
|
replyMessageID?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FileContent {
|
||||||
|
blob: Blob;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AllowedMentions {
|
export interface AllowedMentions {
|
||||||
/** An array of allowed mention types to parse from the content. */
|
/** An array of allowed mention types to parse from the content. */
|
||||||
parse: ("roles" | "users" | "everyone")[];
|
parse: ("roles" | "users" | "everyone")[];
|
||||||
|
|||||||
Reference in New Issue
Block a user