Merge branch 'dev'
This commit is contained in:
commit
24d7ca22a6
8 changed files with 38 additions and 21 deletions
|
@ -18,9 +18,9 @@ export const booruConfig: IBooruConfigMap = {
|
||||||
autocomplete: "ac.rule34.xxx/autocomplete.php?q=",
|
autocomplete: "ac.rule34.xxx/autocomplete.php?q=",
|
||||||
},
|
},
|
||||||
"realbooru.com": {
|
"realbooru.com": {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
name: "realbooru.com",
|
name: "realbooru.com",
|
||||||
aliases: ["realbooru", "rb", "real34"],
|
aliases: ["realbooru", "rb", "real34", "realb"],
|
||||||
endpoint: "realbooru.com",
|
endpoint: "realbooru.com",
|
||||||
functions: booruDefaults,
|
functions: booruDefaults,
|
||||||
autocomplete: "realbooru.com/index.php?page=autocomplete&term=",
|
autocomplete: "realbooru.com/index.php?page=autocomplete&term=",
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
import dotenv from "dotenv";
|
|
||||||
|
|
||||||
import { logger } from "@/helpers/logger";
|
import { logger } from "@/helpers/logger";
|
||||||
|
|
||||||
try {
|
|
||||||
dotenv.config();
|
|
||||||
} catch {
|
|
||||||
logger.error("No .env file found consider creating one");
|
|
||||||
}
|
|
||||||
|
|
||||||
export const environment: Environment = {
|
export const environment: Environment = {
|
||||||
port: parseInt(process.env.PORT || "6600", 10),
|
port: parseInt(process.env.PORT || "6600", 10),
|
||||||
host: process.env.HOST || "0.0.0.0",
|
host: process.env.HOST || "0.0.0.0",
|
||||||
|
|
|
@ -281,12 +281,16 @@ async function handler(
|
||||||
const parsedData: Data = data as Data;
|
const parsedData: Data = data as Data;
|
||||||
|
|
||||||
let posts: BooruPost[] = [];
|
let posts: BooruPost[] = [];
|
||||||
if (parsedData.post) {
|
if (booruConfig.name === "realbooru.com") {
|
||||||
posts = [parsedData.post];
|
posts = parsedData.post || [];
|
||||||
} else if (parsedData.posts) {
|
|
||||||
posts = parsedData.posts;
|
|
||||||
} else {
|
} else {
|
||||||
posts = Array.isArray(data) ? (data as 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) continue;
|
if (posts.length === 0) continue;
|
|
@ -1,15 +1,25 @@
|
||||||
const routeDef: RouteDef = {
|
const routeDef: RouteDef = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
accepts: "*/*",
|
accepts: "*/*",
|
||||||
returns: "text/html",
|
returns: "application/json",
|
||||||
};
|
};
|
||||||
|
|
||||||
async function handler(): Promise<Response> {
|
async function handler(): Promise<Response> {
|
||||||
return new Response("Hello, World!", {
|
return Response.json(
|
||||||
headers: {
|
{
|
||||||
"content-type": "text/html",
|
success: true,
|
||||||
|
code: 200,
|
||||||
|
message:
|
||||||
|
"Welcome to the booru API, check the documentation for more information",
|
||||||
|
links: {
|
||||||
|
forgejo: "https://forgejo.creations.works/creations/booru-api",
|
||||||
|
GitHub: "https://github.com/Creationsss/booru-api",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { handler, routeDef };
|
export { handler, routeDef };
|
||||||
|
|
|
@ -149,11 +149,22 @@ class ServerHandler {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const headers: Headers = response.headers;
|
||||||
|
let ip: string | null = server.requestIP(request)?.address || null;
|
||||||
|
|
||||||
|
if (!ip) {
|
||||||
|
ip =
|
||||||
|
headers.get("CF-Connecting-IP") ||
|
||||||
|
headers.get("X-Real-IP") ||
|
||||||
|
headers.get("X-Forwarded-For") ||
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info([
|
logger.info([
|
||||||
`[${request.method}]`,
|
`[${request.method}]`,
|
||||||
request.url,
|
request.url,
|
||||||
`${response.status}`,
|
`${response.status}`,
|
||||||
server.requestIP(request)?.address || "unknown",
|
`(${ip || "unknown"})`,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
Loading…
Add table
Reference in a new issue