diff options
Diffstat (limited to 'src/api/e621')
-rw-r--r-- | src/api/e621/index.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/api/e621/index.ts b/src/api/e621/index.ts index c8e0f44..411edae 100644 --- a/src/api/e621/index.ts +++ b/src/api/e621/index.ts | |||
@@ -26,7 +26,23 @@ export const client = got.extend({ | |||
26 | }, | 26 | }, |
27 | }); | 27 | }); |
28 | 28 | ||
29 | export async function randomPost() { | 29 | export async function getPost(id: number) { |
30 | const response = await client | ||
31 | .get("https://e926.net/posts.json", { | ||
32 | searchParams: { | ||
33 | tags: `id:${id}`, | ||
34 | }, | ||
35 | }) | ||
36 | .json<{ posts: readonly Post[] }>(); | ||
37 | |||
38 | if (!response.posts.length) { | ||
39 | throw new Error("No posts received"); | ||
40 | } | ||
41 | |||
42 | return response.posts[0]; | ||
43 | } | ||
44 | |||
45 | export async function getRandomPost() { | ||
30 | const queryIndex = Math.floor(Math.random() * config.e621.queries.length); | 46 | const queryIndex = Math.floor(Math.random() * config.e621.queries.length); |
31 | const query = config.e621.queries[queryIndex]; | 47 | const query = config.e621.queries[queryIndex]; |
32 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; | 48 | const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; |