diff --git a/.github/workflows/releases.yaml b/.github/workflows/releases.yaml index 5ac28b6..528aaba 100644 --- a/.github/workflows/releases.yaml +++ b/.github/workflows/releases.yaml @@ -1,6 +1,6 @@ name: Node.js Package env: - APPVERSION: v1.0.${{ github.run_number }} + APPVERSION: v1.1.${{ github.run_number }} on: workflow_dispatch: push: diff --git a/example/imagine.ts b/example/imagine.ts index 21720f8..7b4ad85 100644 --- a/example/imagine.ts +++ b/example/imagine.ts @@ -14,9 +14,12 @@ async function main() { process.env.SALAI_TOKEN, true ); - const msg = await client.Imagine("A little pink elephant", (uri: string) => { - console.log("loading", uri); - }); + const msg = await client.Imagine( + "A little white elephant", + (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); + } + ); console.log({ msg }); } main().catch((err) => { diff --git a/example/upscale.ts b/example/upscale.ts index 8051a86..8f40751 100644 --- a/example/upscale.ts +++ b/example/upscale.ts @@ -25,8 +25,8 @@ async function main() { 2, msg.id, msg.hash, - (uri: string) => { - console.log("loading", uri); + (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); } ); console.log({ msg2 }); diff --git a/package.json b/package.json index 6da4557..79e407a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "midjourney", - "version": "1.0.0", + "version": "1.1.0", "description": "Node.js client for the unofficial MidJourney API.", "main": "libs/index.js", "types": "libs/index.d.ts", diff --git a/src/interfaces/message.ts b/src/interfaces/message.ts index dfe0993..0edbd0a 100644 --- a/src/interfaces/message.ts +++ b/src/interfaces/message.ts @@ -8,4 +8,7 @@ export interface MJMessage { uri: string; hash: string; content: string; + progress?: string; } + +export type LoadingHandler = (uri: string, progress: string) => void; diff --git a/src/midjourney.message.ts b/src/midjourney.message.ts index 19a3cbd..dd85567 100644 --- a/src/midjourney.message.ts +++ b/src/midjourney.message.ts @@ -1,4 +1,4 @@ -import { MJMessage } from "./interfaces"; +import { LoadingHandler, MJMessage } from "./interfaces"; import { CreateQueue } from "./queue"; import { sleep } from "./utls"; @@ -18,7 +18,7 @@ export class MidjourneyMessage { } async FilterMessages( prompt: string, - loading?: (uri: string) => void, + loading?: LoadingHandler, options?: string, index?: number ) { @@ -35,8 +35,7 @@ export class MidjourneyMessage { options && !( item.content.includes(options) || - (options === "Upscaled" && - item.content.includes(` - Image #${index}`)) + (options === "Upscaled" && item.content.includes(`Image #${index}`)) ) ) { this.log("no options"); @@ -48,7 +47,16 @@ export class MidjourneyMessage { } const imageUrl = item.attachments[0].url; if (!imageUrl.endsWith(".png")) { - loading?.(imageUrl); + 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"); + } + loading?.(imageUrl, progress); break; } const content = item.content.split("**")[1]; @@ -57,6 +65,7 @@ export class MidjourneyMessage { uri: imageUrl, hash: this.UriToHash(imageUrl), content: content, + progress: "done", }; return msg; } @@ -66,7 +75,7 @@ export class MidjourneyMessage { UriToHash(uri: string) { return uri.split("_").pop()?.split(".")[0] ?? ""; } - async WaitMessage(prompt: string, loading?: (uri: string) => void) { + async WaitMessage(prompt: string, loading?: LoadingHandler) { for (let i = 0; i < this.maxWait; i++) { const msg = await this.FilterMessages(prompt, loading); if (msg !== null) { @@ -80,7 +89,7 @@ export class MidjourneyMessage { async WaitOptionMessage( content: string, options: string, - loading?: (uri: string) => void + loading?: LoadingHandler ) { for (let i = 0; i < this.maxWait; i++) { const msg = await this.FilterMessages(content, loading, options); @@ -94,7 +103,7 @@ export class MidjourneyMessage { async WaitUpscaledMessage( content: string, index: number, - loading?: (uri: string) => void + loading?: LoadingHandler ) { for (let i = 0; i < this.maxWait; i++) { const msg = await this.FilterMessages(