Compare commits
3 Commits
839fb4c4b7
...
e7f0af8e6e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7f0af8e6e | ||
|
|
3bd0d79fdc | ||
|
|
1e213ddbc4 |
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user