rsshub
Version:
Make RSS Great Again!
103 lines (101 loc) • 4.02 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.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 xxhash from "xxhash-wasm";
//#region lib/routes/picnob.info/user.ts
const route = {
path: "/user/:id/:type?",
categories: ["social-media"],
example: "/picnob.info/user/xlisa_olivex",
parameters: {
id: "Instagram id",
type: {
description: "Type of profile page",
default: "posts",
options: [{
label: "Posts",
value: "posts"
}, {
label: "Stories",
value: "stories"
}]
}
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "User Profile - Picnob",
maintainers: ["TonyRL"],
handler,
view: ViewType.Pictures,
url: "picnob.info"
};
const renderVideo = (video, poster) => `<video controls poster="${poster}"><source src="${video}" type="video/mp4"></video>`;
const renderImage = (src) => `<img src="${src}">`;
const renderDescription = (type, item) => {
let media = "";
switch (type) {
case "carousel":
media = item.albumItems?.map((albumItem) => {
if (albumItem.mediaType === "video") return renderVideo(albumItem.videoUrl, albumItem.thumbnailImageUrl);
return renderImage(albumItem.thumbnailImageUrl);
}).join("<br>");
break;
case "video":
media = renderVideo(item.videoUrl, item.thumbnailImageUrl);
break;
default: media = renderImage(item.thumbnailImageUrl);
}
return `${media}<br>${item.text?.replaceAll("\n", "<br>") ?? ""}`;
};
async function handler(ctx) {
const baseUrl = "https://picnob.info";
const id = ctx.req.param("id");
const type = ctx.req.param("type") ?? "posts";
const INSTALKER_BACK_API_KEY = "1263fd960207e2d481eff2c60feeae1541f6e90419283f7e674a36d8ac706462";
const { h64ToString } = await xxhash();
if (type !== "posts" && type !== "stories") throw new Error("Invalid type parameter. Allowed values are \"posts\" and \"stories\".");
const requestHash = await cache_default.tryGet(`picnob.info:pulls:${id}`, async () => {
return (await ofetch_default(`${baseUrl}/api/v1/pulls`, {
headers: { "x-api-key": INSTALKER_BACK_API_KEY },
method: "POST",
body: {
account: id,
type: "all",
isPrivate: false
}
})).request_hash;
}, config.cache.routeExpire, false);
for (let attempt = 0; attempt < 10; attempt++) {
const status = await ofetch_default(`${baseUrl}/api/v1/pulls/${requestHash}/status`, { headers: { "x-api-key": INSTALKER_BACK_API_KEY } });
if (Array.isArray(status) && status.every((item) => item.status === "success")) break;
if (attempt < 9) await new Promise((resolve) => setTimeout(resolve, 3e3));
}
const profile = await cache_default.tryGet(`picnob.info:profile:${id}`, () => ofetch_default(`${baseUrl}/api/v1/accounts/${id}/profile`, { headers: { "x-api-key": INSTALKER_BACK_API_KEY } }), config.cache.contentExpire);
const items = (await cache_default.tryGet(`picnob.info:${type}:${id}`, () => ofetch_default(`${baseUrl}/api/v1/accounts/${id}/${type}`, { headers: { "x-api-key": INSTALKER_BACK_API_KEY } }), config.cache.routeExpire, false)).map((item) => ({
title: item.text?.split("\n")[0],
guid: item.id ?? h64ToString(`${item.account_name}:${item.takenAt}:${item.thumbnailImageUrl}`),
author: item.account_name,
pubDate: parseDate(item.takenAt),
description: renderDescription(item.postType ?? item.mediaType, item)
}));
return {
title: `${profile.fullName} (@${id}) ${type === "stories" ? "story" : "public"} posts - Picnob`,
description: profile.biography.replaceAll("\n", " "),
link: `https://www.instagram.com/${id}/`,
image: profile.profilePicHdImageId ?? profile.profilePicImageId,
item: items
};
}
//#endregion
export { route };