diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/e926/index.ts (renamed from src/api/e621/index.ts) | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/api/e621/index.ts b/src/api/e926/index.ts index a8abbcf..43a3179 100644 --- a/src/api/e621/index.ts +++ b/src/api/e926/index.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import got from "got"; | 1 | import got from "got"; |
2 | import config from "../../config"; | 2 | import config from "../../config"; |
3 | import delay from "../../util/delay"; | 3 | import delay from "../../util/delay"; |
4 | import dedupe from "../../services/dedupe"; | 4 | import PostDatabase from "../../services/postDatabase"; |
5 | |||
6 | export const dedupeDb = new PostDatabase("e926dedupe.json", 50); | ||
5 | 7 | ||
6 | export interface GetPostQuery { | 8 | export interface GetPostQuery { |
7 | tags: readonly string[]; | 9 | tags: readonly string[]; |
@@ -49,7 +51,7 @@ export async function getPostById(id: number) { | |||
49 | return response.posts[0]; | 51 | return response.posts[0]; |
50 | } | 52 | } |
51 | 53 | ||
52 | export async function getRandomPost(query: GetPostQuery) { | 54 | export async function getRandomPost(query: GetPostQuery): Promise<Post> { |
53 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; | 55 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; |
54 | 56 | ||
55 | const response = await client | 57 | const response = await client |
@@ -69,7 +71,7 @@ export async function getRandomPost(query: GetPostQuery) { | |||
69 | const postIndex = Math.floor(Math.random() * response.posts.length); | 71 | const postIndex = Math.floor(Math.random() * response.posts.length); |
70 | const post = response.posts[postIndex]; | 72 | const post = response.posts[postIndex]; |
71 | 73 | ||
72 | const isDupe = await dedupe.check({ provider: "e926", id: post.id }); | 74 | const isDupe = await dedupeDb.insertIfNotExists({ provider: "e926", id: post.id }); |
73 | 75 | ||
74 | if (isDupe) { | 76 | if (isDupe) { |
75 | await delay(1000); | 77 | await delay(1000); |