From 58bdd17d127cd79f89b5811a4f015b563062eb25 Mon Sep 17 00:00:00 2001 From: Olivier Schiavo Date: Wed, 25 Oct 2023 11:44:54 +0200 Subject: [PATCH] Allow progress updates without images, for 2x and 4x upscales for example --- src/discord.ws.ts | 15 +++++++++++++++ src/interfaces/config.ts | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/discord.ws.ts b/src/discord.ws.ts index be05b57..ae5ea34 100644 --- a/src/discord.ws.ts +++ b/src/discord.ws.ts @@ -433,6 +433,21 @@ export class WsMessage { event.prompt = content; //not image if (!attachments || attachments.length === 0) { + + const progress = content2progress(content); + + if (( this.config.UpdateProgressWithoutImage ) && ( progress !== "" )) { + const MJmsg: MJMessage = { + uri: this.config.EmptyImageUri ? this.config.EmptyImageUri : "", + content: content, + flags: flags, + progress: progress, + }; + const eventMsg: MJEmit = { + message: MJmsg, + }; + this.emitImage(event.nonce, eventMsg); + } return; } diff --git a/src/interfaces/config.ts b/src/interfaces/config.ts index ff97ee5..d1f7132 100644 --- a/src/interfaces/config.ts +++ b/src/interfaces/config.ts @@ -22,6 +22,8 @@ export interface MJConfig { ApiInterval: number; WebSocket: WebSocketCl; ImageProxy: string; + UpdateProgressWithoutImage?: boolean; + EmptyImageUri?: string; } export interface MJConfigParam { SalaiToken: string; //DISCORD_TOKEN @@ -41,6 +43,8 @@ export interface MJConfigParam { WsBaseUrl?: string; fetch?: FetchFn; //Node.js<18 need node.fetch Or proxy WebSocket?: WebSocketCl; //isomorphic-ws Or proxy + UpdateProgressWithoutImage?: boolean; // Send progress even if no image ( upscale 2x, 4x ) + EmptyImageUri?: string; // Uri for image progress when no image is available } export const DefaultMJConfig: MJConfig = { @@ -58,4 +62,6 @@ export const DefaultMJConfig: MJConfig = { WsBaseUrl: "wss://gateway.discord.gg/?encoding=json&v=9", fetch: fetch, WebSocket: WebSocket, + UpdateProgressWithoutImage: false, + EmptyImageUri: "about:blank", };