fix: multiple tags issue
This commit is contained in:
@@ -49,13 +49,13 @@ 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);
|
||||
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, {
|
||||
async function requestRaw(url: string) {
|
||||
const response = await fetch(url, {
|
||||
headers: { "Accept": "application/json" },
|
||||
});
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { assert } from "@std/assert/assert";
|
||||
import {requestJSON, postUrl, ImageResponse} from "./api.ts"
|
||||
|
||||
|
||||
const keys = ["limit" , "id" , "pid" , "tags"] as const
|
||||
type PostKeys = typeof keys[number]
|
||||
|
||||
@@ -36,7 +35,8 @@ export function requestParser(requestString: string) {
|
||||
res[0]
|
||||
.split(",")
|
||||
.forEach(param => {
|
||||
const match = param.match(/\s*(\w+)\s*:\s*([\w+,]+)/)
|
||||
const match = param.match(/\s*(\w+)\s*:\s*([\w+,+]+)/)
|
||||
console.debug({match})
|
||||
if (match !== null) {
|
||||
if (match[1] === undefined || match[2] === undefined) throw Error("Unreachable")
|
||||
if (!isKey(match[1])) throw Error(`Key: ${match[1]} is not a Key!`)
|
||||
@@ -48,13 +48,21 @@ export function requestParser(requestString: string) {
|
||||
} else {
|
||||
throw Error("Request String had some major issues chief")
|
||||
}
|
||||
console.debug()
|
||||
return map
|
||||
}
|
||||
|
||||
// + is replaced with a space... this is pain
|
||||
// see percent code + === 2B
|
||||
export function generateRequestURL(requestString: string) {
|
||||
const postCpy = new URL(postUrl.toString())
|
||||
postCpy.search = new URLSearchParams([...postCpy.searchParams, ...requestParser(requestString)]).toString()
|
||||
return postCpy.toString()
|
||||
|
||||
for (const [k, v] of requestParser(requestString)){
|
||||
postCpy.searchParams.append(k, v)
|
||||
}
|
||||
console.debug(postCpy.searchParams.toString())
|
||||
console.debug({postCpy})
|
||||
return postCpy.href.toString().replaceAll("%2B", '+')
|
||||
}
|
||||
|
||||
Deno.test("Test Request Parser", () => {
|
||||
@@ -72,3 +80,7 @@ Deno.test("Test Drop", async() => {
|
||||
Deno.test("Test Request Workder", async() => {
|
||||
console.debug(await requestWorker("[limit: 12,tags:sfw]"))
|
||||
})
|
||||
|
||||
Deno.test("Test Request Workder 2", async() => {
|
||||
console.debug(await requestWorker("[limit: 5,tags: AI+catgirl]"))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user