UNPKG

rsshub

Version:
145 lines (142 loc) • 5.39 kB
import "./dist-Bog6z_OM.mjs"; import { t as config } from "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { t as config_not_found_default } from "./config-not-found-zoFMPvbz.mjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import markdownit from "markdown-it"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/iwara/templates/subscriptions.tsx const renderSubscriptionImages = (images) => { return renderToString(/* @__PURE__ */ jsx(Fragment, { children: images.filter(Boolean).map((image) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("img", { src: image }), /* @__PURE__ */ jsx("br", {})] })) })); }; //#endregion //#region lib/routes/iwara/subscriptions.ts const md = markdownit({ html: true }); const route = { path: "/subscriptions", categories: ["anime"], example: "/iwara/subscriptions", parameters: {}, features: { requireConfig: [{ name: "IWARA_USERNAME", description: "" }, { name: "IWARA_PASSWORD", description: "" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, radar: [{ source: ["www.iwara.tv/subscriptions/videos", "www.iwara.tv/subscriptions/images"] }], name: "User Subscriptions", maintainers: ["FeCCC"], handler, url: "www.iwara.tv/", description: `::: warning This route requires username and password, therefore it's only available when self-hosting, refer to the [Deploy Guide](https://docs.rsshub.app/deploy/config#route-specific-configurations) for route-specific configurations. :::` }; async function handler() { if (!config.iwara || !config.iwara.username || !config.iwara.password) throw new config_not_found_default("Iwara subscription RSS is disabled due to the lack of <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config</a>"); const rootUrl = "https://www.iwara.tv"; const username = config.iwara.username; const password = config.iwara.password; const refreshHeaders = await cache_default.tryGet("iwara:token", async () => { return { authorization: "Bearer " + (await ofetch_default("https://api.iwara.tv/user/login", { method: "post", headers: { referer: "https://www.iwara.tv/", "user-agent": config.trueUA }, body: { email: username, password } })).token }; }, 720 * 60 * 60, false); const videoSubUrl = "https://api.iwara.tv/videos?rating=all&page=0&limit=24&subscribed=true"; const imageSubUrl = "https://api.iwara.tv/images?rating=all&page=0&limit=24&subscribed=true"; const authHeaders = await cache_default.tryGet("iwara:authToken", async () => { return { authorization: "Bearer " + (await ofetch_default("https://api.iwara.tv/user/token", { method: "post", headers: { ...refreshHeaders, referer: "https://www.iwara.tv/", "user-agent": config.trueUA } })).accessToken }; }, 3600, false); const videoResponse = await ofetch_default(videoSubUrl, { headers: authHeaders }); const imageResponse = await ofetch_default(imageSubUrl, { headers: { ...authHeaders, "user-agent": config.trueUA } }); const videoList = videoResponse.results.map((item) => { const imageUrl = item.file ? `https://i.iwara.tv/image/original/${item.file.id}/thumbnail-${item.thumbnail.toString().padStart(2, "0")}.jpg` : ""; return { title: item.title, author: item.user.name, link: `${rootUrl}/video/${item.id}`, category: ["Video", ...item.tags ? item.tags.map((i) => i.id) : []], imageUrl, pubDate: parseDate(item.createdAt), private: item.private }; }); const imageList = imageResponse.results.map((item) => { const imageUrl = item.thumbnail ? `https://i.iwara.tv/image/original/${item.thumbnail.id}/${item.thumbnail.name}` : ""; return { title: item.title, author: item.user.name, link: `${rootUrl}/image/${item.id}`, category: ["Image", ...item.tags ? item.tags.map((i) => i.id) : []], imageUrl, pubDate: parseDate(item.createdAt) }; }); const list = [...videoList, ...imageList]; return { title: "Iwara Subscription", link: rootUrl, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { let description = renderSubscriptionImages([item.imageUrl]); if (item.private === true) { description += "private"; return { title: item.title, author: item.author, link: item.link, category: item.category, pubDate: item.pubDate, description }; } const response = await ofetch_default(item.link.replace("www.iwara.tv", "api.iwara.tv"), { headers: { ...authHeaders, "user-agent": config.trueUA } }); description = renderSubscriptionImages(response.files ? response.files.filter((f) => f.type === "image")?.map((f) => `https://i.iwara.tv/image/original/${f.id}/${f.name}`) : [item.imageUrl]); const body = response.body ? md.render(response.body) : ""; description += body; return { title: item.title, author: item.author, link: item.link, category: item.category, pubDate: item.pubDate, description }; }))) }; } //#endregion export { route };