rsshub
Version:
Make RSS Great Again!
87 lines (85 loc) • 2.59 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
//#region lib/routes/pixabay/search.ts
init_esm_shims();
const route = {
path: "/search/:q/:order?",
categories: ["picture"],
view: ViewType.Pictures,
example: "/pixabay/search/cat",
parameters: {
q: "Search term",
order: {
description: "Order",
options: [{
value: "popular",
label: "popular"
}, {
value: "latest",
label: "latest"
}],
default: "latest"
}
},
features: {
requireConfig: [{
name: "PIXABAY_KEY",
optional: true,
description: ""
}],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["pixabay.com/:searchType/search/:q"],
target: "/search/:q"
}],
name: "Search",
maintainers: ["TonyRL"],
handler
};
async function handler(ctx) {
const { q, order = "latest" } = ctx.req.param();
const key = config.pixabay?.key ?? "7329690-bbadad6d872ba577d5a358679";
const baseUrl = "https://pixabay.com";
const items = (await cache_default.tryGet(`pixabay:search:${q}:${order}`, async () => {
const { data } = await got_default(`${baseUrl}/api/`, { searchParams: {
key,
q,
order,
per_page: ctx.req.query("limit") ?? 200
} });
return data;
}, Math.max(config.cache.contentExpire, 1440 * 60), false)).hits.map((item) => {
const { pageURL, tags, user } = item;
return {
title: pageURL.substring(pageURL.lastIndexOf("/", pageURL.lastIndexOf("/") - 1) + 1, pageURL.lastIndexOf("/")).replace(/(-\d+)$/, "").replaceAll("-", " "),
description: art(path.join(__dirname, "templates/img-f35220fe.art"), { item }),
link: pageURL,
category: tags.split(", "),
author: user
};
});
return {
title: `Search ${q} - Pixabay`,
description: "Download & use free nature stock photos in high resolution ✓ New free images everyday ✓ HD to 4K ✓ Best nature pictures for all devices on Pixabay",
link: `${baseUrl}/images/search/${q}/${order === "latest" ? "?order=latest" : ""}`,
image: `https://pixabay.com/apple-touch-icon.png`,
language: "en",
item: items
};
}
//#endregion
export { route };