UNPKG

rsshub

Version:
67 lines (64 loc) 2.41 kB
import "./config-C37vj7VH.mjs"; import { t as logger_default } from "./logger-Czu8UMNd.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./proxy-Db7uGcYb.mjs"; import { n as puppeteer_default } from "./puppeteer-DGmvuGvT.mjs"; //#region lib/routes/fortnite/news.ts const route = { path: "/news/:options?", categories: ["game"], example: "/fortnite/news", parameters: { options: "Params" }, features: { requireConfig: false, requirePuppeteer: true, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "News", maintainers: ["lyqluis"], handler, description: `- \`options.lang\`, optional, language, eg. \`/fortnite/news/lang=en-US\`, common languages are listed below, more languages are available one the [official website](https://www.fortnite.com/news) | English (default) | Spanish | Japanese | French | Korean | Polish | | ----------------- | ------- | -------- | ------ | ------ | ------ | | en-US | es-ES | ja | fr | ko | pl |` }; async function handler(ctx) { const options = ctx.req.param("options")?.split("&").map((op) => op.split("=")); const rootUrl = "https://www.fortnite.com"; const path = "news"; const language = options?.find((op) => op[0] === "lang")[1] ?? "en-US"; const link = `${rootUrl}/${path}?lang=${language}`; const apiUrl = `https://www.fortnite.com/api/blog/getPosts?category=&postsPerPage=0&offset=0&locale=${language}&rootPageSlug=blog`; const browser = await puppeteer_default(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on("request", (request) => { request.resourceType() === "document" ? request.continue() : request.abort(); }); let data; page.on("response", async (res) => { data = await res.json(); }); logger_default.http(`Requesting ${apiUrl}`); await page.goto(apiUrl, { waitUntil: "networkidle0" }); await page.close(); await browser.close(); const { blogList: list } = data; return { title: "Fortnite News", link, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, () => ({ title: item.title, link: `${rootUrl}/${path}/${item.slug}?lang=${language}`, pubDate: parseDate(item.date), author: item.author, description: item.content })))) }; } //#endregion export { route };