diff --git a/src/midjourney.message.ts b/src/midjourney.message.ts index fc373cb..f652e1c 100644 --- a/src/midjourney.message.ts +++ b/src/midjourney.message.ts @@ -58,14 +58,7 @@ export class MidjourneyMessage { item.components.length === 0 ) { this.log(`content`, item.content); - const regex = /\(([^)]+)\)/; // matches the value inside the first parenthesis - const match = item.content.match(regex); - let progress = "wait"; - if (match) { - progress = match[1]; - } else { - this.log("No match found"); - } + const progress = this.content2progress(item.content); loading?.(imageUrl, progress); break; } @@ -83,6 +76,20 @@ export class MidjourneyMessage { } return null; } + protected content2progress(content: string) { + const spcon = content.split("**"); + if (spcon.length < 3) { + return ""; + } + content = spcon[2]; + const regex = /\(([^)]+)\)/; // matches the value inside the first parenthesis + const match = content.match(regex); + let progress = ""; + if (match) { + progress = match[1]; + } + return progress; + } UriToHash(uri: string) { return uri.split("_").pop()?.split(".")[0] ?? ""; } diff --git a/src/ws.message.ts b/src/ws.message.ts index d48bc84..d9ffa6e 100644 --- a/src/ws.message.ts +++ b/src/ws.message.ts @@ -254,6 +254,11 @@ export class WsMessage { } protected content2progress(content: string) { + const spcon = content.split("**"); + if (spcon.length < 3) { + return ""; + } + content = spcon[2]; const regex = /\(([^)]+)\)/; // matches the value inside the first parenthesis const match = content.match(regex); let progress = "";