rsshub
Version:
Make RSS Great Again!
109 lines (107 loc) • 3.23 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/hostmonit/cloudflareyes.ts
init_esm_shims();
const lines = {
CM: "中国移动",
CU: "中国联通",
CT: "中国电信"
};
const route = {
path: "/cloudflareyes/:type?",
categories: ["other"],
example: "/hostmonit/cloudflareyes",
parameters: { type: "类型,见下表,默认为 v4" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "CloudFlareYes",
maintainers: ["nczitzk"],
handler,
description: `| v4 | v6 |
| -- | -- |
| | v6 |`
};
async function handler(ctx) {
const { type = "v4" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30;
const domain = "hostmonit.com";
const title = `CloudFlareYes${type === "v6" ? type.toUpperCase() : ""}`;
const rootUrl = `https://stock.${domain}`;
const rootApiUrl = `https://api.${domain}`;
const apiUrl = new URL("get_optimization_ip", rootApiUrl).href;
const currentUrl = new URL(title, rootUrl).href;
const { data: response } = await got_default.post(apiUrl, { json: {
key: "iDetkOys",
...type === "v6" ? { type: "v6" } : {}
} });
const items = response.info.slice(0, limit).map((item) => {
const ip = item.ip;
const latency = item.latency === void 0 ? void 0 : `${item.latency}ms`;
const line = item.line === void 0 ? void 0 : Object.hasOwn(lines, item.line) ? lines[item.line] : item.line;
const loss = item.loss === void 0 ? void 0 : `${item.loss}%`;
const node = item.node;
const speed = item.speed === void 0 ? void 0 : `${item.speed} KB/s`;
const pubDate = timezone(parseDate(item.time), 8);
return {
title: art(path.join(__dirname, "templates/title-c8d56156.art"), {
line,
latency,
loss,
speed,
node,
ip
}),
link: currentUrl,
description: art(path.join(__dirname, "templates/description-0589dc12.art"), {
line,
node,
ip,
latency,
loss,
speed
}),
author: node,
category: [
line,
latency,
loss,
node
].filter(Boolean),
guid: `${domain}-${title}-${ip}#${pubDate.toISOString()}`,
pubDate
};
});
const { data: currentResponse } = await got_default(currentUrl);
const $ = load(currentResponse);
const icon = new URL($("link[rel=\"icon\"]").prop("href"), rootUrl).href;
return {
item: items,
title: $("title").text().replace(/- .*$/, `- ${title}`),
link: currentUrl,
description: $("meta[name=\"description\"]").prop("content"),
language: $("html").prop("lang"),
icon,
logo: icon,
subtitle: title,
author: $("title").text().split(/\s-/)[0],
allowEmpty: true
};
}
//#endregion
export { route };