shoulda finished id, move route
This commit is contained in:
parent
645e0a0d2b
commit
1cba63df34
4 changed files with 118 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
import { determineBooru } from "@helpers/char";
|
||||
import { determineBooru, postExpectedFormat } from "@helpers/char";
|
||||
import { fetch } from "bun";
|
||||
|
||||
import { redis } from "@/database/redis";
|
||||
|
@ -116,14 +116,41 @@ async function handler(
|
|||
);
|
||||
}
|
||||
|
||||
// let keyString = Array.isArray(data) ? "posts" : "post";
|
||||
const parsedData: Data = data as Data;
|
||||
|
||||
let posts: BooruPost[] = [];
|
||||
if (parsedData.post) {
|
||||
posts = [parsedData.post];
|
||||
} else if (parsedData.posts) {
|
||||
posts = parsedData.posts;
|
||||
} else {
|
||||
posts = Array.isArray(data) ? (data as BooruPost[]) : [];
|
||||
}
|
||||
|
||||
if (posts.length === 0) {
|
||||
return Response.json(
|
||||
{
|
||||
success: false,
|
||||
code: 404,
|
||||
error: "Post not found",
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const expectedData: { posts: BooruPost[] } | null = postExpectedFormat(
|
||||
booruConfig,
|
||||
posts,
|
||||
);
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
success: true,
|
||||
code: 200,
|
||||
cache: false,
|
||||
data,
|
||||
post: expectedData?.posts[0] || null,
|
||||
},
|
||||
{
|
||||
status: 200,
|
Loading…
Add table
Add a link
Reference in a new issue