rsshub
Version:
Make RSS Great Again!
110 lines (107 loc) • 3.85 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat.js";
import "dayjs/locale/zh-cn.js";
import timezone from "dayjs/plugin/timezone.js";
import utc from "dayjs/plugin/utc.js";
//#region lib/routes/mi/utils.ts
init_esm_shims();
dayjs.extend(localizedFormat);
dayjs.extend(timezone);
dayjs.extend(utc);
/**
* 获取众筹项目列表
*
* @returns {Promise<CrowdfundingList[]>} 众筹项目列表。
*/
const getCrowdfundingList = async () => {
return (await ofetch_default("https://m.mi.com/v1/crowd/crowd_home", {
headers: { referrer: "https://m.mi.com/" },
method: "POST"
})).data.list;
};
/**
* 获取众筹项目详情并缓存
*
* @param {CrowdfundingItem} item - 众筹项目。
* @returns {Promise<CrowdfundingDetailInfo>} 众筹项目详情。
*/
const getCrowdfundingItem = (item) => cache_default.tryGet(`mi:crowdfunding:${item.project_id}`, async () => {
const response = await ofetch_default("https://m.mi.com/v1/crowd/crowd_detail", {
headers: { referrer: "https://m.mi.com/crowdfunding/home" },
method: "POST",
query: { project_id: item.project_id }
});
if (response.data.crowd_funding_info.product_market_price === void 0) response.data.crowd_funding_info.product_market_price = item.product_market_price;
if (response.data.crowd_funding_info.start_time_desc === void 0) response.data.crowd_funding_info.start_time_desc = formatDate(response.data.crowd_funding_info.start_time);
if (response.data.crowd_funding_info.end_time_desc === void 0) response.data.crowd_funding_info.end_time_desc = formatDate(response.data.crowd_funding_info.end_time);
return response.data.crowd_funding_info;
});
/**
* 渲染众筹项目模板
*
* @param {CrowdfundingDetailInfo} item - 众筹项目详情。
* @returns {string} 渲染后的众筹项目模板字符串。
*/
const renderCrowdfunding = (item) => art(path.join(__dirname, "templates/crowdfunding-a2440baa.art"), item);
const formatDate = (timestamp) => dayjs.unix(timestamp).tz("Asia/Shanghai").locale("zh-cn").format("lll");
var utils_default = {
getCrowdfundingList,
getCrowdfundingItem,
renderCrowdfunding
};
//#endregion
//#region lib/routes/mi/crowdfunding.ts
const route = {
path: "/crowdfunding",
categories: ["shopping"],
example: "/mi/crowdfunding",
name: "小米众筹",
maintainers: ["DIYgod", "nuomi1"],
handler,
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["m.mi.com/crowdfunding/home"],
target: "/crowdfunding"
}],
view: ViewType.Notifications
};
const getDetails = async (list) => {
const result = list.flatMap((section) => section.items.map((item) => utils_default.getCrowdfundingItem(item)));
return await Promise.all(result);
};
const getDataItem = (item) => ({
title: item.project_name,
description: utils_default.renderCrowdfunding(item),
link: `https://m.mi.com/crowdfunding/proddetail/${item.project_id}`,
image: item.big_image,
language: "zh-cn"
});
async function handler() {
return {
title: "小米众筹",
link: "https://m.mi.com/crowdfunding/home",
item: (await getDetails(await utils_default.getCrowdfundingList())).map((item) => getDataItem(item)),
allowEmpty: true,
image: "https://m.mi.com/static/img/icons/apple-touch-icon-152x152.png",
language: "zh-cn"
};
}
//#endregion
export { route };