refactor: streamline API request handling and enhance message processing

This commit is contained in:
fzzin
2025-04-08 18:48:16 +02:00
parent 1e8f195714
commit 79750ed5cc
4 changed files with 157 additions and 110 deletions

View File

@@ -1,5 +1,57 @@
import { assert } from "@std/assert/assert";
import { requestJSON, requestRaw } from "@root/structures/apiRequest.ts";
import { requestJSON } from "@root/structures/apiRequest.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 requestJSON(url)
}
const baseURL = "https://yande.re"
const postURL = `${baseURL}/post.json?api_version=2`;