UNPKG

rsshub

Version:
102 lines (100 loc) 3.73 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import "./md5-C8GRvctM.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import "./config-not-found-Dyp3RlZZ.mjs"; import { a as getFilteredLanguages, i as toQueryString, o as _access_default, r as getMangaMetaByIds, s as _constants_default } from "./_feed-Dvn7_0BR.mjs"; //#region lib/routes/mangadex/user/feed.ts const DEFAULT_LIMIT = 25; const route = { path: "/user/feed/follow/:lang?", name: " Follows Feed", maintainers: ["chrisis58"], description: "Get the latest updates of all the manga you follow on MangaDex.", example: "/mangadex/user/feed/follow/zh?limit=10", radar: [{ source: ["mangadex.org/titles/feed"], target: "/user/feed/follow" }], categories: ["anime"], parameters: { lang: { description: "The language of the followed manga" } }, features: { requireConfig: [ { name: "MANGADEX_USERNAME", description: "MangaDex Username, required when refresh-token is not set", optional: true }, { name: "MANGADEX_PASSWORD", description: "MangaDex Password, required when refresh-token is not set", optional: true }, { name: "MANGADEX_CLIENT_ID", description: "MangaDex Client ID", optional: false }, { name: "MANGADEX_CLIENT_SECRET", description: "MangaDex Client Secret", optional: false }, { name: "MANGADEX_REFRESH_TOKEN", description: "MangaDex Refresh Token, required when username and password are not set", optional: true } ], nsfw: true }, handler }; async function handler(ctx) { const userFollowUrl = `${_constants_default.API.BASE}/user/follows/manga/feed`; const { lang } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : DEFAULT_LIMIT; const accessToken = await _access_default(); const languagesQuery = new Set([...typeof lang === "string" ? [lang] : lang || [], ...await getFilteredLanguages()].filter(Boolean)); const feed = await cache_default.tryGet("mangadex:user-follows", async () => { const followedChapterFeed = (await got_default.get(`${userFollowUrl}${toQueryString({ translatedLanguage: languagesQuery, order: { publishAt: "desc" }, limit })}`, { headers: { Authorization: `Bearer ${accessToken}`, "User-Agent": config.trueUA } }))?.data?.data; if (!followedChapterFeed) throw new Error("Failed to retrieve user follows from MangaDex API."); return followedChapterFeed; }, config.cache.routeExpire, false); const mangaMetas = await getMangaMetaByIds(feed.map((chapter) => chapter?.relationships.find((relationship) => relationship.type === "manga")?.id)); return { title: "User Follows", link: "https://mangadex.org/titles/feed", description: "The latest updates of all the manga you follow on MangaDex.", item: feed.map((chapter) => { const mangaId = chapter.relationships.find((relationship) => relationship.type === "manga")?.id; const mangaMeta = mangaMetas.get(mangaId); const chapterTitile = [ chapter.attributes.volume ? `Vol. ${chapter.attributes.volume}` : null, chapter.attributes.chapter ? `Ch. ${chapter.attributes.chapter}` : null, chapter.attributes.title ].filter(Boolean).join(" "); return { title: mangaMeta?.title || "Unknown", link: `${_constants_default.API.MANGA_CHAPTERS}${chapter.id}`, pubDate: new Date(chapter.attributes.publishAt), description: chapterTitile, image: mangaMeta?.cover }; }) }; } //#endregion export { route };