From 1e213ddbc46a5a348181cab5b8edb7cfd58bb9a1 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 29 Nov 2025 01:20:48 +0800 Subject: [PATCH] feat get mimetype --- client-protocol/Message.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client-protocol/Message.ts b/client-protocol/Message.ts index 9511d9d..ea5729a 100644 --- a/client-protocol/Message.ts +++ b/client-protocol/Message.ts @@ -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 parseInt(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()