import { handlePostRequest } from "@root/plugins/yandere/api/post.ts"; const baseURL = "https://yande.re"; const apikeys = [ "post", "tags", "artist", "comments", "wiki", "notes", "users", "forum", "pools", ] as const; type APIKeys = typeof apikeys[number]; function prepareURLObjectForRequest(type: APIKeys) { const tmp = new URL(baseURL); tmp.searchParams.append("api_version", "3"); switch (type) { case "post": tmp.pathname = "post.json"; break; case "tags": tmp.pathname = "tag.json"; break; case "artist": tmp.pathname = "artist.json"; break; case "comments": tmp.pathname = "comment"; break; case "wiki": tmp.pathname = "wiki.json"; break; case "notes": tmp.pathname = "note.json"; break; case "users": tmp.pathname = "user.json"; break; case "forum": tmp.pathname = "forum.json"; break; case "pools": tmp.pathname = "pool.json"; break; default: throw Error("unknown "); } return tmp; } export function getPosts(search? : string){ const url = prepareURLObjectForRequest("post") return handlePostRequest(url, search) } Deno.test("Empty Post Request", async() => { console.debug(await getPosts()) }) Deno.test("Post Request with tag", async() => { console.debug(await getPosts("[tags:love_live!_(series)]")) }) Deno.test("Post Request with limit", async() => { console.debug(await getPosts("[limit: 1)]")) })