UNPKG

rsshub

Version:
86 lines (85 loc) 2.83 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as config } from "./config-Bpyy15zS.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { s as solveWafChallenge } from "./utils-BImtW9k-.mjs"; import { n as queryToBoolean } from "./readable-social-DP5kGwF5.mjs"; import { t as renderUserEmbed } from "./user-C1ehbvl0.mjs"; import { load } from "cheerio"; //#region lib/routes/tiktok/user.ts const baseUrl = "https://www.tiktok.com"; const route = { path: "/user/:user/:iframe?", categories: ["social-media"], example: "/tiktok/user/@linustech/true", parameters: { user: "User ID, including @", iframe: "Use the official iframe to embed the video, which allows you to view the video if the default option does not work. Default to `false`" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.tiktok.com/:user"], target: "/user/:user" }], name: "User", maintainers: ["TonyRL"], handler }; async function handler(ctx) { const { user, iframe } = ctx.req.param(); const useIframe = queryToBoolean(iframe); const handle = user.startsWith("@") ? user : `@${user}`; const path = `/embed/${handle}`; const profile = await cache_default.tryGet(`tiktok:user:${handle}`, async () => { let response = await rofetch(baseUrl + path); let $ = load(response); if ($("p#wci").hasClass("_wafchallengeid")) { const cookie = solveWafChallenge($("p#cs").attr("class")); response = await rofetch(baseUrl + path, { headers: { cookie: `_wafchallengeid=${cookie};` } }); $ = load(response); } const { userInfo, videoList } = JSON.parse($("script#__FRONTITY_CONNECT_STATE__").text()).source.data[path]; return { nickname: userInfo.nickname, uniqueId: userInfo.uniqueId, signature: userInfo.signature, avatar: userInfo.avatarThumbUrl, videos: videoList.map((video) => ({ id: video.id, desc: video.desc, cover: video.coverUrl, playAddr: video.playAddr, authorUniqueId: video.authorUniqueId, createTime: Number(BigInt(video.id) >> 32n) })) }; }, config.cache.routeExpire, false); const items = profile.videos.map((video) => ({ title: video.desc, description: renderUserEmbed({ poster: video.cover, source: video.playAddr, useIframe, id: video.id }), author: profile.nickname, pubDate: parseDate(video.createTime, "X"), link: `${baseUrl}/@${video.authorUniqueId}/video/${video.id}` })); return { title: `${profile.nickname} (@${profile.uniqueId}) | TikTok`, description: profile.signature, image: profile.avatar, link: `${baseUrl}/@${profile.uniqueId}`, item: items }; } //#endregion export { route };