Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #90 from TeamSekai/patch/77-upload-unsupported-med…
Browse files Browse the repository at this point in the history
…ia-type

/uploadコマンドが一部ファイルに対応していない問題を修正 (#77)
  • Loading branch information
ringo360 authored Apr 9, 2024
2 parents b66a612 + eb32fc1 commit 470a778
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions packages/cdn/upload.js → packages/cdn/upload.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { SlashCommandBuilder } = require('discord.js');
const axios = require('axios').default;
const FormData = require('form-data');
const config = require('../../config.json');
const { LANG, strFormat } = require('../../util/languages');
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import axios from 'axios';
import FormData from 'form-data';
import config from '../../internal/config';
import { LANG, strFormat } from '../../util/languages';

module.exports = {
export default {
data: new SlashCommandBuilder()
.setName(LANG.commands.upload.name)
.setDescription(LANG.commands.upload.description)
Expand All @@ -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;
Expand All @@ -46,18 +43,18 @@ module.exports = {
);

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.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);
form.append('file', Buffer.from(resData), filename || file.name);
const res2 = await axios.post(config.cdnUploadURL, form, {
params: {
private: isPrivate,
Expand Down

0 comments on commit 470a778

Please sign in to comment.