From c840800485d7c6df073dd1f16d03d8ceffabeea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E9=9B=AA=E6=AE=87=E7=92=83=E9=99=8C=E6=A2=A6?= Date: Mon, 24 Jul 2023 15:01:07 +0800 Subject: [PATCH] fix: fix image transfer --- src/messanger.ts | 2 +- src/utils/transferImage.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/messanger.ts b/src/messanger.ts index bd5e524..053e418 100644 --- a/src/messanger.ts +++ b/src/messanger.ts @@ -186,7 +186,7 @@ export class VillaMessanger extends Messenger { } case "image": { const url = (element.attrs as Dict)["url"]; - const newUrl = await this.bot.transferImage(url); + const newUrl = await this.bot.transferImage(url, this.villaId); const { protocol } = new URL(newUrl); if (protocol !== "http:" && protocol !== "https:") throw new Error(`Unsupported image protocol: ${protocol}`); diff --git a/src/utils/transferImage.ts b/src/utils/transferImage.ts index 3ad9926..e2bc661 100644 --- a/src/utils/transferImage.ts +++ b/src/utils/transferImage.ts @@ -14,6 +14,7 @@ const images: Record = {}; export async function transferImage( this: VillaBot, url: string, + villaId: string, ): Promise { const { hostname, protocol } = new URL(url); let hash: string | undefined, sourceUrl: string; @@ -87,9 +88,13 @@ export async function transferImage( await this.axios.axios( "/vila/api/bot/platform/transferImage", { + method: "POST", data: defineStruct({ url: sourceUrl, }), + headers: { + "x-rpc-bot_villa_id": villaId, + }, validateStatus: (status) => (status >= 200 && status < 300) || status === 429, },