rsshub
Version:
Make RSS Great Again!
101 lines (99 loc) • 3.3 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.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 got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
//#region lib/routes/misskey/utils.ts
init_esm_shims();
const allowSiteList = [
"misskey.io",
"madost.one",
"mk.nixnet.social"
];
const parseNotes = (data, site, simplifyAuthor = false) => data.map((item) => {
const isRenote = item.renote && Object.keys(item.renote).length > 0;
const isReply = item.reply && Object.keys(item.reply).length > 0;
const noteToUse = isRenote ? item.renote : item;
const host = noteToUse.user.host ?? site;
const author = simplifyAuthor ? String(noteToUse.user.name) : `${noteToUse.user.name} (${noteToUse.user.username}@${host})`;
const description = art(path.join(__dirname, "templates/note-b4364264.art"), {
text: noteToUse.text,
files: noteToUse.files,
reply: item.reply,
site
});
let title = "";
if (isReply && item.reply) {
const replyToHost = item.reply.user.host ?? site;
title = `Reply to ${simplifyAuthor ? item.reply.user.name : `${item.reply.user.name} (${item.reply.user.username}@${replyToHost})`}: "${noteToUse.text ?? ""}"`;
} else if (isRenote) title = `Renote: ${author}: "${noteToUse.text ?? ""}"`;
else title = `${author}: "${noteToUse.text ?? ""}"`;
/**
* For renotes from non-Misskey instances (e.g. Mastodon, Pleroma),
* we can't use noteToUse.id to link to the original note since:
* 1. The URL format differs from Misskey's /notes/{id} pattern
* 2. Direct access to the original note may not be possible
* Therefore, we link to the renote itself in such cases
*/
let noteId = noteToUse.id;
if (isRenote) {
const renoteHost = item.user.host ?? site;
const noteHost = noteToUse.user.host ?? site;
if (renoteHost !== noteHost || !allowSiteList.includes(noteHost)) noteId = item.id;
}
const link = `https://${host}/notes/${noteId}`;
const pubDate = parseDate(noteToUse.createdAt);
return {
title,
description,
pubDate,
link,
author
};
});
async function getUserTimelineByUsername(username, site, { withRenotes = false, mediaOnly = false }) {
const searchUrl = `https://${site}/api/users/search-by-username-and-host`;
const cacheUid = `misskey_username/${site}/${username}`;
const userData = await cache_default.tryGet(cacheUid, async () => {
const user = (await got_default({
method: "post",
url: searchUrl,
json: {
username,
host: site,
detail: true,
limit: 1
}
})).data.find((item) => item.username === username);
if (!user) throw new Error(`username ${username} not found`);
return user;
});
const accountId = userData.id;
const avatarUrl = userData.avatarUrl;
return {
site,
accountId,
accountData: (await got_default({
method: "post",
url: `https://${site}/api/users/notes`,
json: {
userId: accountId,
withChannelNotes: true,
withRenotes,
withReplies: !mediaOnly,
withFiles: mediaOnly,
limit: 10,
offset: 0
}
})).data,
avatarUrl
};
}
var utils_default = {
parseNotes,
getUserTimelineByUsername,
allowSiteList
};
//#endregion
export { utils_default as t };