Skip to content

Commit

Permalink
fix: fix image transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamOfIce committed Jul 24, 2023
1 parent c6bf934 commit c840800
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/messanger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class VillaMessanger extends Messenger<VillaBot> {
}
case "image": {
const url = (element.attrs as Dict<string, "url">)["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}`);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/transferImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const images: Record<string, ArrayBuffer> = {};
export async function transferImage(
this: VillaBot,
url: string,
villaId: string,
): Promise<string> {
const { hostname, protocol } = new URL(url);
let hash: string | undefined, sourceUrl: string;
Expand Down Expand Up @@ -87,9 +88,13 @@ export async function transferImage(
await this.axios.axios<API.TransferImage.Response>(
"/vila/api/bot/platform/transferImage",
{
method: "POST",
data: defineStruct<API.TransferImage.Request>({
url: sourceUrl,
}),
headers: {
"x-rpc-bot_villa_id": villaId,
},
validateStatus: (status) =>
(status >= 200 && status < 300) || status === 429,
},
Expand Down

0 comments on commit c840800

Please sign in to comment.