Autodetect mime type for m->d stickers

This commit is contained in:
Cadence Ember 2023-09-30 16:21:07 +13:00
parent c9bc6ac629
commit 7a218f1254
2 changed files with 14 additions and 7 deletions

View file

@ -457,12 +457,19 @@ async function eventToMessage(event, guild, di) {
} }
} else if (event.type === "m.sticker") { } else if (event.type === "m.sticker") {
content = "" 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) const url = utils.getPublicUrlForMxc(event.content.url)
assert(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}) attachments.push({id: "0", filename})
pendingFiles.push({name: filename, url}) pendingFiles.push({name: filename, url})
} }

6
types.d.ts vendored
View file

@ -139,8 +139,8 @@ export namespace Event {
export type M_Sticker = { export type M_Sticker = {
body: string body: string
url: string url: string
info: { info?: {
mimetype: string mimetype?: string
w?: number w?: number
h?: number h?: number
size?: number size?: number
@ -217,7 +217,7 @@ export namespace R {
} }
} }
export type Pagination<T> { export type Pagination<T> = {
chunk: T[] chunk: T[]
next_batch?: string next_batch?: string
prev_match?: string prev_match?: string