Compare commits

..

2 Commits

Author SHA1 Message Date
CrescentLeaf
35afcf03bb fix: wrong Message instance 2025-11-29 00:56:28 +08:00
CrescentLeaf
5864108f99 fix(cp): marked import 2025-11-29 00:56:08 +08:00
2 changed files with 30 additions and 5 deletions

View File

@@ -8,7 +8,7 @@ import UserMySelf from "./UserMySelf.ts"
import CallbackError from "./CallbackError.ts" import CallbackError from "./CallbackError.ts"
import Chat from "./Chat.ts" import Chat from "./Chat.ts"
import { CallableMethodBeforeAuth } from "lingchair-internal-shared" import { CallableMethodBeforeAuth } from "lingchair-internal-shared"
import Message from "./Message.ts"; import Message from "./Message.ts"
export { export {
User, User,
@@ -53,7 +53,7 @@ export default class LingChairClient {
for (const v of (this.events[name] || [])) for (const v of (this.events[name] || []))
v(({ v(({
"Client.onMessage": { "Client.onMessage": {
message: new Message(this, data) message: new Message(this, data.msg)
} }
})[name]) })[name])
} catch (e) { } catch (e) {

View File

@@ -6,7 +6,7 @@ import User from "./User.ts"
import CallbackError from "./CallbackError.ts" import CallbackError from "./CallbackError.ts"
import ApiCallbackMessage from "./ApiCallbackMessage.ts" import ApiCallbackMessage from "./ApiCallbackMessage.ts"
import marked from 'marked' import * as marked from 'marked'
class ChatMention extends BaseClientObject { class ChatMention extends BaseClientObject {
declare chat_id?: string declare chat_id?: string
@@ -61,9 +61,12 @@ class ChatAttachment extends BaseClientObject {
return null return null
} }
} }
async blobOrThrow() { fetch(init?: RequestInit) {
const url = this.client.getUrlForFileByHash(this.file_hash) 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() const blob = await re.blob()
if (!re.ok) throw new CallbackError({ if (!re.ok) throw new CallbackError({
msg: await blob.text(), msg: await blob.text(),
@@ -71,6 +74,28 @@ class ChatAttachment extends BaseClientObject {
} as ApiCallbackMessage) } as ApiCallbackMessage)
return blob 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() { getFileHash() {
return this.file_hash return this.file_hash
} }