Autodetect mime type for m->d stickers
This commit is contained in:
parent
c9bc6ac629
commit
7a218f1254
2 changed files with 14 additions and 7 deletions
|
@ -457,12 +457,19 @@ async function eventToMessage(event, guild, di) {
|
|||
}
|
||||
} else if (event.type === "m.sticker") {
|
||||
content = ""
|
||||
let filename = event.content.body
|
||||
if (event.type === "m.sticker" && event.content.info.mimetype.includes("/")) {
|
||||
filename += "." + event.content.info.mimetype.split("/")[1]
|
||||
}
|
||||
const url = utils.getPublicUrlForMxc(event.content.url)
|
||||
assert(url)
|
||||
let filename = event.content.body
|
||||
if (event.type === "m.sticker") {
|
||||
let mimetype
|
||||
if (event.content.info?.mimetype?.includes("/")) {
|
||||
mimetype = event.content.info.mimetype
|
||||
} else {
|
||||
const res = await fetch(url, {method: "HEAD"})
|
||||
mimetype = res.headers.get("content-type") || "image/webp"
|
||||
}
|
||||
filename += "." + mimetype.split("/")[1]
|
||||
}
|
||||
attachments.push({id: "0", filename})
|
||||
pendingFiles.push({name: filename, url})
|
||||
}
|
||||
|
|
6
types.d.ts
vendored
6
types.d.ts
vendored
|
@ -139,8 +139,8 @@ export namespace Event {
|
|||
export type M_Sticker = {
|
||||
body: string
|
||||
url: string
|
||||
info: {
|
||||
mimetype: string
|
||||
info?: {
|
||||
mimetype?: string
|
||||
w?: number
|
||||
h?: number
|
||||
size?: number
|
||||
|
@ -217,7 +217,7 @@ export namespace R {
|
|||
}
|
||||
}
|
||||
|
||||
export type Pagination<T> {
|
||||
export type Pagination<T> = {
|
||||
chunk: T[]
|
||||
next_batch?: string
|
||||
prev_match?: string
|
||||
|
|
Loading…
Reference in a new issue