UNPKG

rsshub

Version:
41 lines (39 loc) 2.06 kB
import { t as config } from "./config-C37vj7VH.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import { Category, MixiClient } from "mixi2"; //#region lib/routes/mixi2/utils.ts function getClient() { const { authToken, authKey } = config.mixi2; if (!authToken || !authKey) throw new config_not_found_default("MIXI2_AUTH_TOKEN and MIXI2_AUTH_KEY are required"); return new MixiClient(`auth_token=${authToken}`, authKey, { httpAdapter: ofetch_default }); } function parsePost(post) { let description = post.text ? `<p>${post.text}</p>` : ""; for (const media of post.medias ?? []) if (media.category === Category.CATEGORY_POST_IMAGE) description += `<img src="${media.postImage?.largeImageUrl ?? media.postImage?.smallImageUrl}"${media.description ? `alt="${media.description}"` : ""} />`; else if (media.category === Category.CATEGORY_POST_VIDEO) description += `<img src="${media.postVideo?.previewImageUrl}" alt="${media.description}" />`; return description; } function generatePostDataItem(post, personas) { const author = personas.find((persona) => persona.personaId === post.personaId); return { description: parsePost(post), pubDate: parseDate(post.createdAt.seconds * 1e3), guid: post.postId, author: author?.name, link: `https://mixi.social/@${author?.name}/posts/${post.postId}` }; } const CONFIG_OPTIONS = [{ name: "MIXI2_AUTH_TOKEN", description: "mixi2ログイン後の情報。ブラウザのコンソールでクッキーから `auth_token` の値を取得してください" }, { name: "MIXI2_AUTH_KEY", description: "mixi2ログイン後の情報。ブラウザのコンソールでリクエストヘッダーから `x-auth-key` の値を取得してください" }]; function postFilter(post) { return !post.isDeleted && post.personaId; } //#endregion export { postFilter as a, parsePost as i, generatePostDataItem as n, getClient as r, CONFIG_OPTIONS as t };