mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
improve performance *a lot*
This commit is contained in:
parent
c586664aaf
commit
100d609793
1 changed files with 21 additions and 21 deletions
|
@ -21,7 +21,7 @@ export default definePlugin({
|
||||||
const currChannel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
|
const currChannel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
|
||||||
if (currChannel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, currChannel)) return null;
|
if (currChannel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, currChannel)) return null;
|
||||||
|
|
||||||
if (![0,19].includes(msg.type) || msg.hasFlag(8192)) return null;
|
if (![0, 19].includes(msg.type) || msg.hasFlag(8192)) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
label: "Add attachments",
|
label: "Add attachments",
|
||||||
|
@ -47,9 +47,9 @@ export default definePlugin({
|
||||||
return input.remove();
|
return input.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
showToast("Uploading...");
|
showToast("Uploading, this can take a while...");
|
||||||
|
|
||||||
async function uploadLoop(file: File) {
|
const uploadPromises = Array.from(input.files).map(async file => {
|
||||||
const attachmentsReq = (await Common.RestAPI.post({
|
const attachmentsReq = (await Common.RestAPI.post({
|
||||||
url: `/channels/${channelId}/attachments`,
|
url: `/channels/${channelId}/attachments`,
|
||||||
body: {
|
body: {
|
||||||
|
@ -69,26 +69,26 @@ export default definePlugin({
|
||||||
body: file
|
body: file
|
||||||
});
|
});
|
||||||
|
|
||||||
const msg = MessageStore.getMessage(channelId, messageId);
|
return {
|
||||||
|
id: attachmentsReq.id,
|
||||||
|
uploaded_filename: attachmentsReq.upload_filename,
|
||||||
|
filename: file.name
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await Common.RestAPI.patch({
|
const newAttachments = await Promise.all(uploadPromises);
|
||||||
url: `/channels/${channelId}/messages/${messageId}`,
|
|
||||||
body: {
|
|
||||||
attachments: [
|
|
||||||
...msg.attachments,
|
|
||||||
{
|
|
||||||
id: attachmentsReq.id,
|
|
||||||
uploaded_filename: attachmentsReq.upload_filename,
|
|
||||||
filename: file.name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < input.files.length; i++) {
|
const msg = MessageStore.getMessage(channelId, messageId);
|
||||||
await uploadLoop(input.files[i]);
|
|
||||||
}
|
await Common.RestAPI.patch({
|
||||||
|
url: `/channels/${channelId}/messages/${messageId}`,
|
||||||
|
body: {
|
||||||
|
attachments: [
|
||||||
|
...msg.attachments,
|
||||||
|
...newAttachments
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
input.remove();
|
input.remove();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue