diff options
-rw-r--r-- | src/api/e621/index.ts | 3 | ||||
-rw-r--r-- | src/util/delay.ts | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/api/e621/index.ts b/src/api/e621/index.ts index 32b7fc0..5c5fd2a 100644 --- a/src/api/e621/index.ts +++ b/src/api/e621/index.ts | |||
@@ -2,6 +2,7 @@ import got from "got"; | |||
2 | import config from "../../config"; | 2 | import config from "../../config"; |
3 | import fs from "fs/promises"; | 3 | import fs from "fs/promises"; |
4 | import path from "path"; | 4 | import path from "path"; |
5 | import delay from "../../util/delay"; | ||
5 | 6 | ||
6 | export interface GetPostQuery { | 7 | export interface GetPostQuery { |
7 | tags: readonly string[]; | 8 | tags: readonly string[]; |
@@ -101,7 +102,7 @@ export async function getRandomPost(query: GetPostQuery) { | |||
101 | const post = response.posts[postIndex]; | 102 | const post = response.posts[postIndex]; |
102 | 103 | ||
103 | if (dedupeDb.includes(post.id)) { | 104 | if (dedupeDb.includes(post.id)) { |
104 | await new Promise((resolve) => setTimeout(resolve, 1000)); | 105 | await delay(1000); |
105 | return getRandomPost(query); | 106 | return getRandomPost(query); |
106 | } | 107 | } |
107 | 108 | ||
diff --git a/src/util/delay.ts b/src/util/delay.ts new file mode 100644 index 0000000..1fc86a2 --- /dev/null +++ b/src/util/delay.ts | |||
@@ -0,0 +1 @@ | |||
export default (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); | |||