Skip to content

Commit

Permalink
fix(discord): downloaded assets should have correct extnames, fix #569
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 4, 2022
1 parent 2c5d54b commit b4dd6e6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions plugins/adapter/discord/src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export class Sender {

async sendEmbed(fileBuffer: ArrayBuffer, payload_json: Dict, filename: string) {
const fd = new FormData()
const type = await fromBuffer(fileBuffer)
filename ||= 'file.' + type.ext
filename ||= 'file.' + (await fromBuffer(fileBuffer)).ext
fd.append('file', fileBuffer, filename)
fd.append('payload_json', JSON.stringify(payload_json))
return this.post(fd, fd.getHeaders())
Expand Down Expand Up @@ -98,12 +97,11 @@ export class Sender {
}

const sendDownload = async () => {
const filename = basename(data.url)
const buffer = await this.bot.app.http.get<ArrayBuffer>(data.url, {
headers: { accept: type + '/*' },
responseType: 'arraybuffer',
})
return this.sendEmbed(buffer, addition, data.file || filename)
return this.sendEmbed(buffer, addition, data.file)
}

const mode = data.mode as HandleExternalAsset || handleExternalAsset
Expand Down

0 comments on commit b4dd6e6

Please sign in to comment.