Export requestJSON and requestRAW to core, formatting and adapting code and removing yandere code for update.

This commit is contained in:
fzzin
2025-04-08 16:27:58 +02:00
parent 8f903af37d
commit 1e8f195714
9 changed files with 70 additions and 147 deletions

View File

@@ -1,5 +1,6 @@
//TODO Add optional extensions like limit at Posts with tags etc.
import * as xml_parser from "jsr:@melvdouc/xml-parser";
import { requestRaw, requestJSON } from "@root/structures/apiRequest.ts";
export type ImageResponse = {
preview_url: string;
@@ -49,22 +50,6 @@ export const postUrl = new URL(`${baseUrl}/index.php?page=dapi&s=post&q=index&js
const tagUrl = `${baseUrl}/index.php?page=dapi&s=tag&q=index`;
const commentsUrl = `${baseUrl}/index.php?page=dapi&s=comment&q=index`;
export async function requestJSON<T>(url: string) {
const response = await requestRaw(url);
return <T> await response.json();
}
async function requestRaw(url: string) {
const response = await fetch(url, {
headers: { "Accept": "application/json" },
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response;
}
//List
// Comments
export async function getPostComments(postID: number): Promise<CommentResponse[]> {
const response = await requestRaw(`${commentsUrl}&post_id=${postID}`);

View File

@@ -1,6 +1,7 @@
import { assert } from "@std/assert/assert";
import { ImageResponse, postUrl, requestJSON } from "./api.ts";
import { requestJSON } from "@root/structures/apiRequest.ts";
import { Embed, EmbedAuthor, EmbedImage } from "@root/structures/embeds.ts";
import { ImageResponse, postUrl } from "./api.ts";
const keys = ["limit", "id", "pid", "tags"] as const;
type PostKeys = typeof keys[number];