From 5864108f99f6fe29991f22caaf24c85fe8be8afa Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 29 Nov 2025 00:56:08 +0800 Subject: [PATCH] fix(cp): marked import --- client-protocol/Message.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/client-protocol/Message.ts b/client-protocol/Message.ts index 205475c..21c25d7 100644 --- a/client-protocol/Message.ts +++ b/client-protocol/Message.ts @@ -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 }