Compare commits

..

3 Commits

Author SHA1 Message Date
CrescentLeaf
e7f0af8e6e idk 2025-11-29 11:23:27 +08:00
CrescentLeaf
3bd0d79fdc wtf fix int wrong stupid 2025-11-29 01:21:56 +08:00
CrescentLeaf
1e213ddbc4 feat get mimetype 2025-11-29 01:20:48 +08:00

View File

@@ -75,6 +75,28 @@ class ChatAttachment extends BaseClientObject {
} as ApiCallbackMessage)
return blob
}
async getMimeType() {
try {
return await this.getMimeTypeOrThrow()
} catch (_) {
return null
}
}
async getMimeTypeOrThrow() {
const re = await this.fetch({
method: 'HEAD'
})
if (re.ok) {
const t = re.headers.get('content-type')
if (t)
return t
throw new Error("Unable to get Content-Type")
}
throw new CallbackError({
msg: await re.text(),
code: re.status,
} as ApiCallbackMessage)
}
async getLength() {
try {
return await this.getLengthOrThrow()
@@ -162,8 +184,8 @@ export default class Message extends BaseClientObject {
if (fileType != null && /tws:\/\/file\?hash=[A-Za-z0-9]+$/.test(href)) {
const file_hash = /^tws:\/\/file\?hash=(.*)/.exec(href)?.[1]!
let file_name: string = /^Video|File|Image=(.*)/.exec(text)?.[1] || text
file_name.trim() == '' && (file_name = 'Unnamed File')
let file_name: string = /^(Video|File|Image)=(.*)/.exec(text)?.[2] || text
file_name.trim() == '' && (file_name = 'Unnamed_File')
return attachment ? attachment({ text: text, attachment: new ChatAttachment(this.client, { file_hash, file_name }), fileType: fileType, }) : text
}
if (mentionType != null && /^tws:\/\/chat\?id=[A-Za-z0-9]+/.test(href)) {