feat(nhentai): add random abstraction
このコミットが含まれているのは:
コミット
0758b406e3
|
@ -0,0 +1,28 @@
|
|||
import { scrapeContent } from "../../scraper/nhentai/nhentaiGetController";
|
||||
import c from "../../utils/options";
|
||||
import { logger } from "../../utils/logger";
|
||||
import { mock } from "../../utils/modifier";
|
||||
import { getIdRandomNhentai } from "../../utils/modifier";
|
||||
|
||||
export async function randomNhentai(req: any, res: any, next: any) {
|
||||
try {
|
||||
let actualAPI;
|
||||
if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP;
|
||||
else actualAPI = c.NHENTAI;
|
||||
|
||||
const id = await getIdRandomNhentai();
|
||||
|
||||
const url = `${actualAPI}/api/gallery/${id}`;
|
||||
const data = await scrapeContent(url);
|
||||
logger.info({
|
||||
path: req.path,
|
||||
query: req.query,
|
||||
method: req.method,
|
||||
ip: req.ip,
|
||||
useragent: req.get("User-Agent")
|
||||
});
|
||||
return res.json(data);
|
||||
} catch (err: any) {
|
||||
next(Error(err.message));
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import { getSimplyhentai } from "../controller/simply-hentai/simply-hentaiGet";
|
|||
import { getNhentai } from "../controller/nhentai/nhentaiGet";
|
||||
import { searchNhentai } from "../controller/nhentai/nhentaiSearch";
|
||||
import { relatedNhentai } from "../controller/nhentai/nhentaiRelated";
|
||||
import { randomNhentai } from "../controller/nhentai/nhentaiRandom";
|
||||
import { slow, limiter } from "../utils/limit-options";
|
||||
|
||||
function scrapeRoutes() {
|
||||
|
@ -27,6 +28,7 @@ function scrapeRoutes() {
|
|||
router.get("/nhentai/get", slow, limiter, getNhentai);
|
||||
router.get("/nhentai/search", slow, limiter, searchNhentai);
|
||||
router.get("/nhentai/related", slow, limiter, relatedNhentai);
|
||||
router.get("/nhentai/random", slow, limiter, randomNhentai);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
|
読み込み中…
新しいイシューから参照