Export requestJSON and requestRAW to core, formatting and adapting code and removing yandere code for update.
This commit is contained in:
@@ -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}`);
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user