From e9c2db0329bdae8762b37b69402cbe5b2d1f6019 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Sun, 7 Apr 2024 21:47:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?ts=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cdn/{upload.js => upload.ts} | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) rename packages/cdn/{upload.js => upload.ts} (95%) diff --git a/packages/cdn/upload.js b/packages/cdn/upload.ts similarity index 95% rename from packages/cdn/upload.js rename to packages/cdn/upload.ts index 19e03d96..f9205c0a 100755 --- a/packages/cdn/upload.js +++ b/packages/cdn/upload.ts @@ -1,10 +1,10 @@ -const { SlashCommandBuilder } = require('discord.js'); +import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; const axios = require('axios').default; const FormData = require('form-data'); const config = require('../../config.json'); const { LANG, strFormat } = require('../../util/languages'); -module.exports = { +export default { data: new SlashCommandBuilder() .setName(LANG.commands.upload.name) .setDescription(LANG.commands.upload.description) @@ -25,10 +25,7 @@ module.exports = { .setDescription(LANG.commands.upload.options.private.description) .setRequired(false), ), - execute: async function ( - /** @type {import('discord.js').CommandInteraction} */ - interaction, - ) { + execute: async function (interaction: ChatInputCommandInteraction) { if (!config.cdnUploadURL || !config.uploadAllowUsers) { await interaction.reply(LANG.commands.upload.internalError); return; From ff9577fca41b1bed635e0d579db3f908ad5ed801 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Sun, 7 Apr 2024 21:56:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?TS=E3=81=AE=E6=9B=B8=E3=81=8D=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cdn/upload.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/cdn/upload.ts b/packages/cdn/upload.ts index f9205c0a..80e47848 100755 --- a/packages/cdn/upload.ts +++ b/packages/cdn/upload.ts @@ -1,8 +1,8 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; -const axios = require('axios').default; -const FormData = require('form-data'); -const config = require('../../config.json'); -const { LANG, strFormat } = require('../../util/languages'); +import axios from 'axios'; +import FormData from 'form-data'; +import config from '../../internal/config'; +import { LANG, strFormat } from '../../util/languages'; export default { data: new SlashCommandBuilder() @@ -47,12 +47,13 @@ export default { responseType: 'stream', }); const form = new FormData(); - const filename = interaction.options.get( + const filename = interaction.options.getString( LANG.commands.upload.options.filename.name, - )?.value; + ); const isPrivate = - interaction.options.get(LANG.commands.upload.options.private.name) - ?.value == true; + interaction.options.getBoolean( + LANG.commands.upload.options.private.name, + ) == true; console.log(strFormat(LANG.commands.upload.isPrivateLog, [isPrivate])); form.append('file', res.data, filename || file.name); const res2 = await axios.post(config.cdnUploadURL, form, { From eb32fc121ddf77c8672de4d6def834c0d5de4040 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:48:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fetch=E3=82=92=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cdn/upload.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/cdn/upload.ts b/packages/cdn/upload.ts index 80e47848..e6202c55 100755 --- a/packages/cdn/upload.ts +++ b/packages/cdn/upload.ts @@ -43,9 +43,8 @@ export default { ); try { - const res = await axios.get(file.proxyURL, { - responseType: 'stream', - }); + const res = await fetch(file.url); + const resData = await res.arrayBuffer(); const form = new FormData(); const filename = interaction.options.getString( LANG.commands.upload.options.filename.name, @@ -55,7 +54,7 @@ export default { LANG.commands.upload.options.private.name, ) == true; console.log(strFormat(LANG.commands.upload.isPrivateLog, [isPrivate])); - form.append('file', res.data, filename || file.name); + form.append('file', Buffer.from(resData), filename || file.name); const res2 = await axios.post(config.cdnUploadURL, form, { params: { private: isPrivate,