From 8a6ad69c1e859db373a67c75f893853986750603 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 18 Oct 2021 13:50:57 +0200 Subject: Support posting a specific picture --- src/api/e621/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/api/e621/index.ts') 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({ }, }); -export async function randomPost() { +export async function getPost(id: number) { + const response = await client + .get("https://e926.net/posts.json", { + searchParams: { + tags: `id:${id}`, + }, + }) + .json<{ posts: readonly Post[] }>(); + + if (!response.posts.length) { + throw new Error("No posts received"); + } + + return response.posts[0]; +} + +export async function getRandomPost() { const queryIndex = Math.floor(Math.random() * config.e621.queries.length); const query = config.e621.queries[queryIndex]; const page = Math.floor(Math.random() * (query.maxPage - 1)) + 1; -- cgit v1.2.3-70-g09d2