This commit is contained in:
fzzinchemical
2025-04-10 17:11:19 +02:00
9 changed files with 228 additions and 209 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,5 +1,7 @@
import { ImageResponse, postUrl, requestJSON } from "./api.ts";
import { assert } from "@std/assert/assert";
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];