rsshub
Version:
Make RSS Great Again!
140 lines (138 loc) • 5.18 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { 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 config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs";
import path from "node:path";
import markdownit from "markdown-it";
//#region lib/routes/iwara/subscriptions.ts
init_esm_shims();
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 = art(path.join(__dirname, "templates/subscriptions-a44731e7.art"), { images: [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 = art(path.join(__dirname, "templates/subscriptions-a44731e7.art"), { images: 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 };