rsshub
Version:
Make RSS Great Again!
63 lines (61 loc) • 2.42 kB
JavaScript
import "./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";
//#region lib/routes/iwara/index.ts
const rootUrl = "https://www.iwara.tv";
const apiRootUrl = "https://api.iwara.tv";
const imageRootUrl = "https://i.iwara.tv";
const typeMap = {
video: "Videos",
image: "Images"
};
const apiUrlMap = {
video: `${apiRootUrl}/videos`,
image: `${apiRootUrl}/images`
};
const parseThumbnail = (type, item) => {
if (type === "image") return `<img src="${imageRootUrl}/image/original/${item.thumbnail.id}/${item.thumbnail.name}">`;
if (item.embedUrl === null) return `<img src="${imageRootUrl}/image/original/${item.file.id}/thumbnail-${String(item.thumbnail).padStart(2, "0")}.jpg">`;
const match = /https?:\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w-]*)(&(amp;)?[\w=?]*)?/.exec(item.embedUrl);
if (match) return `<img src="${imageRootUrl}/image/embed/original/youtube/${match[1]}">`;
return "";
};
const route = {
path: "/users/:username/:type?",
example: "/iwara/users/kelpie/video",
parameters: {
username: "username, can find in userpage",
type: "content type, can be video or image, default is video"
},
name: "User",
maintainers: ["Fatpandac"],
handler,
features: { nsfw: true }
};
async function handler(ctx) {
const { username, type = "video" } = ctx.req.param();
const id = (await cache_default.tryGet(`${apiRootUrl}/profile/${username}`, async () => {
return (await ofetch_default(`${apiRootUrl}/profile/${username}`, { headers: { "user-agent": config.trueUA } })).user;
})).id;
const items = (await cache_default.tryGet(`${apiUrlMap[type]}?user=${id}`, async () => {
return (await ofetch_default(`${apiUrlMap[type]}?user=${id}`, { headers: { "user-agent": config.trueUA } })).results;
}, config.cache.routeExpire, false)).map((item) => ({
title: item.title,
author: username,
link: `${rootUrl}/${type}/${item.id}/${item.slug}`,
category: item.tags.map((i) => i.id),
description: parseThumbnail(type, item),
pubDate: parseDate(item.createdAt)
}));
return {
title: `${username}'s iwara - ${typeMap[type]}`,
link: `${rootUrl}/users/${username}`,
item: items
};
}
//#endregion
export { route };