rsshub
Version:
Make RSS Great Again!
62 lines (60 loc) • 3.19 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { n as parseRelativeDate, t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/thepaper/utils.ts
init_esm_shims();
const defaultRssItem = (item) => ({
title: item.name,
link: item.link,
description: item.name,
pubDate: parseDate(item.pubTimeLong),
media: { content: { url: item.pic } }
});
var utils_default = {
ProcessItem: (item, ctx) => {
const useOldMode = ctx.req.query("old") === "yes";
if (item.link) return defaultRssItem(item);
const itemUrl = `https://m.thepaper.cn/${item.cornerLabelDesc && item.cornerLabelDesc === "短剧" ? "series" : "detail"}/${item.contId}`;
return cache_default.tryGet(`${itemUrl}${useOldMode ? ":old" : ""}`, async () => {
const res = await got_default(itemUrl);
const detailData = JSON.parse(load(res.data)("#__NEXT_DATA__").html()).props.pageProps.detailData;
const contentDetail = detailData.contentDetail || detailData.liveDetail || detailData.specialDetail?.specialInfo;
if (!contentDetail) return defaultRssItem(item);
let description = contentDetail.content || contentDetail.summary || contentDetail.desc || "";
if (contentDetail.videos) description = description + contentDetail.summary;
if (useOldMode) {
if (contentDetail.videos) description = art(path.join(__dirname, "templates/video_detail-6e02b70e.art"), { videos: contentDetail.videos }) + description;
if (contentDetail.images) description = art(path.join(__dirname, "templates/image_detail-7a807b2d.art"), { images: contentDetail.images }) + description;
}
let pubDate = parseDate(item.pubTimeLong || contentDetail.publishTime);
if (Number.isNaN(pubDate)) pubDate = parseRelativeDate(contentDetail.pubTime);
const rss_item = {
title: contentDetail.name || contentDetail.shareName,
link: itemUrl,
description,
category: [...contentDetail.tagList?.map((t) => t.tag) ?? [], contentDetail?.nodeInfo?.name ?? []],
pubDate,
author: contentDetail.author || "",
media: {
content: { url: item.pic || contentDetail.videos?.coverUrl || contentDetail.bigPic },
thumbnails: { url: item.sharePic || contentDetail.sharePic }
}
};
if (contentDetail.voiceInfo?.isHaveVoice) {
rss_item.enclosure_type = "audio/mpeg";
rss_item.enclosure_url = contentDetail.voiceInfo.voiceSrc;
rss_item.itunes_item_image = item.pic || contentDetail.videos?.coverUrl;
}
return rss_item;
});
},
ChannelIdToName: (nodeId, next_data) => next_data.props.appProps.menu.channelList.find((c) => c.nodeId.toString() === nodeId.toString()).name,
ListIdToName: (listId, next_data) => next_data.props.appProps.menu.channelList.flatMap((c) => c.childNodeList || []).find((l) => l.nodeId.toString() === listId.toString())?.name,
ExtractLogo: (response) => "https://m.thepaper.cn" + load(response.data)("img.imageCover").attr("src")
};
//#endregion
export { utils_default as t };