Skip to content

Commit bbd9786

Browse files
committed
feat: support props interval and update default timeout and interval
1 parent 19340e9 commit bbd9786

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "midjourney-fetch",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "",
55
"type": "module",
66
"main": "./dist/index.js",

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const configs = {
2-
timeout: 2 * 60 * 1000, // 2min
3-
interval: 2 * 1000, // every 2 second
2+
timeout: 5 * 60 * 1000, // 5 min
3+
interval: 15 * 1000, // every 15 second
44
};

src/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export interface MidjourneyProps {
66
channelId: string;
77
serverId: string;
88
token: string;
9-
timeout?: number; // default timeout: 2 min
9+
timeout?: number; // default timeout: 5 min
10+
interval?: number; // default interval: 15s
1011
}
1112

1213
export interface MessageAttachment {

src/midjourney.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ export class Midjourney {
1515

1616
timeout: number;
1717

18+
interval: number;
19+
1820
debugger: boolean;
1921

2022
constructor(props: MidjourneyProps) {
21-
const { channelId, serverId, token, timeout = configs.timeout } = props;
23+
const {
24+
channelId,
25+
serverId,
26+
token,
27+
timeout = configs.timeout,
28+
interval = configs.interval,
29+
} = props;
2230
this.channelId = channelId;
2331
this.serverId = serverId;
2432
this.token = token;
33+
2534
this.timeout = timeout;
35+
this.interval = interval;
36+
2637
this.debugger = false;
2738
}
2839

@@ -120,13 +131,13 @@ export class Midjourney {
120131
*/
121132
async imagine(prompt: string) {
122133
await this.interactions(prompt);
123-
const times = this.timeout / configs.interval;
134+
const times = this.timeout / this.interval;
124135
let count = 0;
125136
let image: MessageAttachment | null = null;
126137
while (count < times) {
127138
try {
128139
count += 1;
129-
await new Promise((res) => setTimeout(res, configs.interval));
140+
await new Promise((res) => setTimeout(res, this.interval));
130141
this.log(count);
131142
const message = await this.getMessage(prompt);
132143
if (message && !isInProgress(message)) {

0 commit comments

Comments
 (0)