rsshub
Version:
Make RSS Great Again!
69 lines (67 loc) • 2.32 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as baseURL } from "./const-48U4nwlg.mjs";
import { load } from "cheerio";
//#region lib/routes/shopify/apps/search.ts
const route = {
path: "/apps/search/:q",
example: "/shopify/apps/search/flow",
parameters: { q: "需要搜索的 App" },
name: "App store search",
maintainers: ["PrintNow"],
handler,
radar: [{
source: ["apps.shopify.com/search"],
target: (_params, url) => {
const searchParams = new URL(url).searchParams;
if (!searchParams.has("q")) return "";
return `/shopify/apps/search/${searchParams.get("q")}`;
}
}]
};
async function handler(ctx) {
const { q = "" } = ctx.req.param();
const $ = load(await (await got_default.get(`${baseURL}/search`, {
searchParams: { q },
headers: {
accept: "text/html, application/xhtml+xml",
"accept-language": "en-US;q=0.9",
"turbo-frame": "search_page",
referer: baseURL,
dnt: "1"
}
})).data);
const items = $(".search-results-component div[data-controller=\"app-card\"]").toArray().map((item) => {
const handle = $(item).attr("data-app-card-handle-value");
const appInfo = $(item).find("div.tw-self-stretch").clone();
const rattingMatch = appInfo.find("span").text().match(/\d\.\d/);
const rattingCountMatch = appInfo.find("span + span.tw-sr-only").text().match(/\d+/);
return {
title: $(item).attr("data-app-card-name-value") ?? "",
link: `${baseURL}/${handle}`,
description: $(item).find(`div.tw-text-fg-tertiary`).first().text().trim(),
image: $(item).attr("data-app-card-icon-url-value"),
_extra: {
handle,
description: $(item).find(`div.tw-text-fg-tertiary`).first().text().trim(),
built_for_shopify: $(item).find(`span.built-for-shopify-badge`).length > 0,
ratting: rattingMatch ? Number.parseFloat(rattingMatch[0]) : 0,
ratting_count: rattingCountMatch ? Number(rattingCountMatch[0]) : 0
}
};
});
return {
title: `Search results for "${q}" – Shopify App Store`,
link: `https://apps.shopify.com/search?q=${q}`,
allowEmpty: true,
language: "en-us",
item: items
};
}
//#endregion
export { route };