Compare commits
2 Commits
d486c9df79
...
35afcf03bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35afcf03bb | ||
|
|
5864108f99 |
@@ -8,7 +8,7 @@ import UserMySelf from "./UserMySelf.ts"
|
||||
import CallbackError from "./CallbackError.ts"
|
||||
import Chat from "./Chat.ts"
|
||||
import { CallableMethodBeforeAuth } from "lingchair-internal-shared"
|
||||
import Message from "./Message.ts";
|
||||
import Message from "./Message.ts"
|
||||
|
||||
export {
|
||||
User,
|
||||
@@ -53,7 +53,7 @@ export default class LingChairClient {
|
||||
for (const v of (this.events[name] || []))
|
||||
v(({
|
||||
"Client.onMessage": {
|
||||
message: new Message(this, data)
|
||||
message: new Message(this, data.msg)
|
||||
}
|
||||
})[name])
|
||||
} catch (e) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import User from "./User.ts"
|
||||
import CallbackError from "./CallbackError.ts"
|
||||
import ApiCallbackMessage from "./ApiCallbackMessage.ts"
|
||||
|
||||
import marked from 'marked'
|
||||
import * as marked from 'marked'
|
||||
|
||||
class ChatMention extends BaseClientObject {
|
||||
declare chat_id?: string
|
||||
@@ -61,9 +61,12 @@ class ChatAttachment extends BaseClientObject {
|
||||
return null
|
||||
}
|
||||
}
|
||||
async blobOrThrow() {
|
||||
fetch(init?: RequestInit) {
|
||||
const url = this.client.getUrlForFileByHash(this.file_hash)
|
||||
const re = await fetch(url!)
|
||||
return fetch(url!, init)
|
||||
}
|
||||
async blobOrThrow() {
|
||||
const re = await this.fetch()
|
||||
const blob = await re.blob()
|
||||
if (!re.ok) throw new CallbackError({
|
||||
msg: await blob.text(),
|
||||
@@ -71,6 +74,28 @@ class ChatAttachment extends BaseClientObject {
|
||||
} as ApiCallbackMessage)
|
||||
return blob
|
||||
}
|
||||
async getLength() {
|
||||
try {
|
||||
return await this.getLengthOrThrow()
|
||||
} catch (_) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
async getLengthOrThrow() {
|
||||
const re = await this.fetch({
|
||||
method: 'HEAD'
|
||||
})
|
||||
if (re.ok) {
|
||||
const contentLength = re.headers.get('content-length')
|
||||
if (contentLength)
|
||||
return parseInt(contentLength)
|
||||
throw new Error("Unable to get Content-Length")
|
||||
}
|
||||
throw new CallbackError({
|
||||
msg: await re.text(),
|
||||
code: re.status,
|
||||
} as ApiCallbackMessage)
|
||||
}
|
||||
getFileHash() {
|
||||
return this.file_hash
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user