UNPKG

rsshub

Version:
117 lines (115 loc) 4.93 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs"; import path from "node:path"; //#region lib/routes/fansly/utils.ts init_esm_shims(); const apiBaseUrl = "https://apiv3.fansly.com"; const baseUrl = "https://fansly.com"; const icon = `${baseUrl}/assets/images/icons/apple-touch-icon.png`; const findAccountById = (accountId, accounts) => { const account = accounts.find((account$1) => account$1.id === accountId); return { displayName: account.displayName, username: account.username }; }; const getAccountByUsername = (username) => cache_default.tryGet(`fansly:account:${username.toLowerCase()}`, async () => { const { data: accountResponse } = await got_default(`${apiBaseUrl}/api/v1/account`, { searchParams: { usernames: username, "ngsw-bypass": true } }); if (!accountResponse.response.length) throw new invalid_parameter_default("This profile or page does not exist."); return accountResponse.response[0]; }); const getTimelineByAccountId = async (accountId) => { const { data: timeline } = await got_default(`${apiBaseUrl}/api/v1/timelinenew/${accountId}`, { searchParams: { before: 0, after: 0, wallId: "", contentSearch: "", "ngsw-bypass": true } }); return timeline.response; }; const getTagId = (tag) => cache_default.tryGet(`fansly:tag:${tag.toLowerCase()}`, async () => { const { data: tagResponse } = await got_default(`${apiBaseUrl}/api/v1/contentdiscovery/media/tag`, { searchParams: { tag, "ngsw-bypass": true } }); if (!tagResponse.response.mediaOfferSuggestionTag) throw new Error("Couldn't find this hashtag."); return tagResponse.response.mediaOfferSuggestionTag.id; }); const getTagSuggestion = async (tagId) => { const { data: suggestionResponse } = await got_default(`${apiBaseUrl}/api/v1/contentdiscovery/media/suggestionsnew`, { searchParams: { before: 0, after: 0, tagIds: tagId, limit: 25, offset: 0, "ngsw-bypass": true } }); return suggestionResponse.response; }; const parseDescription = (post, aggregationData) => post.content.replaceAll("\n", "<br>") + "<br>" + parseAttachments(post.attachments, aggregationData); const parseAttachments = (attachments, aggregationData) => attachments.map((attachment) => { switch (attachment.contentType) { case 1: return parseMedia(attachment.contentId, aggregationData.accountMedia); case 2: { let attachments$1 = ""; const bundle = aggregationData.accountMediaBundles.find((bundle$1) => bundle$1.id === attachment.contentId); for (const mediaId of bundle.accountMediaIds) attachments$1 += parseMedia(mediaId, aggregationData.accountMedia); return attachments$1; } case 8: { let attachments$1 = "<br><br>"; const repost = aggregationData.aggregatedPosts.find((post) => post.id === attachment.contentId) || aggregationData.posts.find((post) => post.id === attachment.contentId); attachments$1 += parseDescription(repost, aggregationData); return attachments$1; } case 7100: return renderTipGoal(attachment.contentId, aggregationData.tipGoals); case 32001: return ""; case 42001: return renderPoll(attachment.contentId, aggregationData.polls); default: throw new Error(`Unhandled attachment type: ${attachment.contentType} for post ${attachment.postId}`); } }).join(""); const parseMedia = (contentId, accountMedia) => { const media = accountMedia.find((media$1) => media$1.id === contentId); if (!media) return ""; return renderMedia(media.preview ?? media.media); }; const renderMedia = (media) => { switch (media.mimetype) { case "image/gif": case "image/jpeg": case "image/png": case "video/mp4": case "audio/mp4": return art(path.join(__dirname, "templates/media-e8ba56ad.art"), { poster: media.mimetype === "video/mp4" ? media.variants[0].locations[0] : null, src: media.locations[0] }); default: throw new Error(`Unhandled media type: ${media.mimetype}`); } }; const renderPoll = (pollId, polls) => { const poll = polls.find((poll$1) => poll$1.id === pollId); return art(path.join(__dirname, "templates/poll-cab99125.art"), { title: poll.question, options: poll.options, version: poll.version }); }; const renderTipGoal = (tipGoalId, tipGoals) => { const goal = tipGoals.find((goal$1) => goal$1.id === tipGoalId); return art(path.join(__dirname, "templates/tip-goal-0ea3f03a.art"), { label: goal.label, description: goal.description, currentAmount: goal.currentAmount, goalAmount: goal.goalAmount, currentPercentage: goal.currentPercentage }); }; //#endregion export { getTagSuggestion as a, parseDescription as c, getTagId as i, findAccountById as n, getTimelineByAccountId as o, getAccountByUsername as r, icon as s, baseUrl as t };