UNPKG

rsshub

Version:
84 lines (81 loc) 2.77 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./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 invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs"; import path from "node:path"; //#region lib/routes/myfans/utils.ts init_esm_shims(); const apiBaseUrl = "https://api.myfans.jp"; const baseUrl = "https://myfans.jp"; const headers = { "google-ga-data": "event328" }; const showByUsername = (username) => cache_default.tryGet(`myfans:account:${username}`, async () => { const accountInfo = await ofetch_default(`${apiBaseUrl}/api/v2/users/show_by_username`, { headers, query: { username } }); if (!accountInfo.id) throw new invalid_parameter_default("This creator does not exist."); return accountInfo; }); const getPostByAccountId = async (accountId) => { return (await ofetch_default(`${apiBaseUrl}/api/v2/users/${accountId}/posts`, { headers, query: { sort_key: "publish_start_at", page: 1 } })).data; }; //#endregion //#region lib/routes/myfans/post.ts const route = { path: "/user/:username", categories: ["multimedia"], example: "/myfans/user/secret_japan", parameters: { username: "User handle" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, radar: [{ source: ["myfans.jp/:username", "myfans.jp/:language/:username"] }], name: "User Posts", maintainers: ["TonyRL"], handler }; const render = (postImages, body) => art(path.join(__dirname, "templates/post-e2e0e95c.art"), { postImages, body }); async function handler(ctx) { const { username } = ctx.req.param(); const account = await showByUsername(username); const items = (await getPostByAccountId(account.id)).map((p) => ({ title: p.body?.replaceAll("\r\n", " ").trim().split(" ")[0], description: render(p.post_images, p.body?.replaceAll("\r\n", "<br>")), pubDate: parseDate(p.published_at), link: `${baseUrl}/posts/${p.id}`, author: p.user.name })); return { title: `${account.name} (@${account.username})`, link: `${baseUrl}/${account.username}`, description: `${account.posts_count} Post ${account.likes_count} Like ${account.followers_count} Followers ${account.followings_count} Follow ${account.about.replaceAll("\r\n", " ")}`, image: account.avatar_url, icon: account.avatar_url, logo: account.avatar_url, language: "ja-JP", item: items }; } //#endregion export { route };