File size: 1,698 Bytes
f535bab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import { sendSuccess, ErrorResponses } from "../../lib/response-helper.js";
import { Komiku } from "./komiku.js"
/** @type {import("../../types/plugin.ts").ApiPluginHandler}*/
const handler = {
name: "Komiku: Search Comic",
method: "GET",
version: "1.0.0",
category: ["komiku"],
alias: ["search"],
tags: ["comic"],
parameters: {
query: [
{
name: "query",
type: "string",
required: true,
description: "Your search, Write a title",
example: "Otonari no tenshi"
}
],
body: [],
headers: []
},
responses: {
200: {
status: 200,
description: "Successfully retrieved data",
example: {
status: 200,
author: "Ditzzy",
note: "Thank you for using this API!",
results: {}
}
},
404: {
status: 404,
description: "Missing required parameter",
example: {
status: 404,
message: "Missing required parameter: ..."
}
},
500: {
status: 500,
description: "Server error or unavailable",
example: {
status: 500,
message: "An error occurred, please try again later."
}
}
},
exec: async (req, res) => {
const { query } = req.query;
if (!query) return ErrorResponses.missingParameter(res, "query");
const komik = new Komiku();
try {
const search = await komik.search(query);
if (search.results === null) return ErrorResponses.notFound(res);
sendSuccess(res, search.results)
} catch (e) {
ErrorResponses.serverError(res, "An error occurred, try again later.");
}
}
}
export default handler;
|