diff options
author | Volpeon <git@volpeon.ink> | 2021-10-19 19:25:03 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-19 19:25:03 +0200 |
commit | 163d8119c109c42e64ab37b01dec131f2cb5bf61 (patch) | |
tree | ee0abce3ce349482ca63b4064fcbebc0e5d2f4ff /src/api | |
parent | Code improvements (diff) | |
download | feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.tar.gz feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.tar.bz2 feralbot-163d8119c109c42e64ab37b01dec131f2cb5bf61.zip |
Code improvements, support a manual post queue
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); |