UNPKG

rsshub

Version:
89 lines (88 loc) 2.96 kB
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/douyin/templates/cover.tsx const renderCover = ({ img, videoList }) => { const videoUrl = videoList?.[0]; return renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [ img ? videoUrl ? /* @__PURE__ */ jsx("a", { href: videoUrl, rel: "noreferrer", children: /* @__PURE__ */ jsx("img", { src: img, style: "width: 50%;" }) }) : /* @__PURE__ */ jsx("img", { src: img, style: "width: 50%;" }) : null, img && videoUrl ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {})] }) : null, videoUrl ? /* @__PURE__ */ jsx("a", { href: videoUrl, rel: "noreferrer", children: "视频直链" }) : null ] })); }; //#endregion //#region lib/routes/douyin/templates/desc.tsx const renderDesc = ({ desc, media }) => renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [ raw(desc), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), raw(media) ] })); //#endregion //#region lib/routes/douyin/templates/embed.tsx const renderEmbed = ({ img, duration, videoList = [] }) => renderToString(/* @__PURE__ */ jsx("video", { controls: true, preload: "metadata", referrerpolicy: "no-referrer", style: "width:50%", poster: img, duration, children: videoList.map((source) => /* @__PURE__ */ jsx("source", { referrerpolicy: "no-referrer", src: source })) })); //#endregion //#region lib/routes/douyin/templates/iframe.tsx const renderIframe = ({ content }) => { return renderToString(/* @__PURE__ */ jsx("iframe", { referrerpolicy: "no-referrer", width: "100%", height: "150vh", frameborder: "0", marginheight: "0", marginwidth: "0", style: "border:0; margin:0; padding:0; width:100%; height:150vh;", srcdoc: `<!DOCTYPE html><html><head><meta name="referrer" content="no-referrer"></head><body>${content}</body></html>` })); }; //#endregion //#region lib/routes/douyin/utils.ts const templates = { desc: renderDesc, cover: renderCover, embed: renderEmbed, iframe: renderIframe }; const resolveUrl = (url, tls = true, forceResolve = false) => { if (!url) return ""; if (url.startsWith("//")) return (tls ? "https:" : "http:") + url; if (forceResolve && !/^https?:\/\//.test(url)) return (tls ? "https://" : "http://") + url; return url; }; const proxyVideo = (url, proxy) => { if (!(url && proxy)) return url + ""; if (proxy.includes("?")) { if (!proxy.endsWith("=")) proxy += "="; return proxy + encodeURIComponent(url); } if (!proxy.endsWith("/")) proxy += "/"; return proxy + url; }; const getOriginAvatar = (url) => resolveUrl(url).replace(/^(.*\.douyinpic\.com\/).*(\/aweme-avatar\/)([^?]*)(\?.*)?$/, "$1origin$2$3").replaceAll(/~\w+_\d+x\d+/g, ""); //#endregion export { templates as i, proxyVideo as n, resolveUrl as r, getOriginAvatar as t };