feat(webui): support custom background images (#6674)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-16 22:08:55 +08:00
1 parent 92d23d2d2b
commit e91906bc3a
29 files changed
+1259 -3

No files matched your search

+17
View File
@@ -742,6 +742,23 @@ export class NanobotClient {
}
}
async uploadBackground(file: File): Promise<void> {
const socket = this.socket;
const capability = this.upload;
const stillConnected = () => this.socket === socket
&& socket?.readyState === WS_OPEN && this.upload === capability;
const dataUrl = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => typeof reader.result === "string" ? resolve(reader.result) : reject(new Error("Could not read image"));
reader.onerror = () => reject(new Error("Could not read image"));
reader.readAsDataURL(file);
});
const [attachment] = await uploadAttachments([{ data_url: dataUrl, name: file.name }], capability,
typeof window !== "undefined" ? window.location.href : this.currentUrl, stillConnected);
if (!attachment || !("reference" in attachment)) throw new Error("Could not upload image");
await this.requestMutation("background.update", { reference: attachment.reference });
}
async sendAttachments(
chatId: string, content: string, media: OutboundMedia[],
options?: Parameters<NanobotClient["sendMessage"]>[3],