2025-02-28 15:42:20 +01:00
|
|
|
/* eslint no-async-promise-executor: 0 */ // Doing promises is needed in order to make multiple requests at once, lowering wait time
|
|
|
|
|
2025-01-22 19:38:42 +01:00
|
|
|
import {type Handler} from "@netlify/functions";
|
2025-02-18 02:14:01 +01:00
|
|
|
import { KitsuclubInfo } from "#Infos/Fediverse/KitsuClub.js";
|
2025-02-17 13:26:10 +01:00
|
|
|
import { api } from "./shared/api.js";
|
2025-01-22 19:38:42 +01:00
|
|
|
|
|
|
|
const handler: Handler = async () => {
|
2025-02-17 13:26:10 +01:00
|
|
|
const kitsuclub = await api<{
|
2025-02-28 12:29:54 +01:00
|
|
|
id: string
|
2025-02-17 13:26:10 +01:00
|
|
|
user: {
|
|
|
|
name: string
|
|
|
|
username: string
|
|
|
|
avatarUrl: string
|
|
|
|
emojis: Record<string, string>
|
|
|
|
}
|
|
|
|
text: string
|
2025-02-28 12:29:54 +01:00
|
|
|
renoteCount: number
|
|
|
|
repliesCount: number
|
|
|
|
reactionCount: number
|
2025-02-17 13:26:10 +01:00
|
|
|
createdAt: string
|
2025-02-28 12:29:54 +01:00
|
|
|
files: {
|
|
|
|
thumbnailUrl: string
|
|
|
|
comment: string
|
|
|
|
}[]
|
2025-02-17 13:26:10 +01:00
|
|
|
}[]>("https://kitsunes.club/api/users/notes", process.env.API_KITSUCLUB, true, JSON.stringify({
|
|
|
|
"userId": "a2hgd7delf",
|
|
|
|
"limit": 1,
|
|
|
|
"withReplies": false,
|
|
|
|
"withRepliesToSelf": false,
|
|
|
|
"withQuotes": true,
|
|
|
|
"withRenotes": false,
|
|
|
|
"withBots": true,
|
|
|
|
"withNonPublic": true,
|
|
|
|
"withChannelNotes": false,
|
|
|
|
"withFiles": false,
|
|
|
|
"allowPartial": false,
|
|
|
|
}));
|
|
|
|
|
2025-02-28 15:42:20 +01:00
|
|
|
const details = kitsuclub.at(Math.max(0, kitsuclub.length - 1));
|
2025-02-17 13:26:10 +01:00
|
|
|
if (!details) {
|
|
|
|
return {
|
|
|
|
statusCode: 404,
|
|
|
|
};
|
|
|
|
}
|
2025-01-22 19:38:42 +01:00
|
|
|
|
2025-02-28 15:42:20 +01:00
|
|
|
let scan_text = details.text;
|
|
|
|
const emojis_to_get: Promise<void>[] = [];
|
|
|
|
while (scan_text.includes(":")) {
|
|
|
|
const index_1 = scan_text.indexOf(":");
|
|
|
|
const index_2 = scan_text.substring(index_1 + 1).indexOf(":");
|
|
|
|
|
|
|
|
if (index_2 === -1) {
|
|
|
|
scan_text = scan_text.substring(index_1 + 1);
|
|
|
|
} else {
|
|
|
|
const potential_emoji = scan_text.substring(index_1 + 1, index_2 + 1);
|
|
|
|
if (!potential_emoji.includes(" ")) {
|
|
|
|
emojis_to_get.push(new Promise(async (resolve) => {
|
|
|
|
try {
|
|
|
|
const fetched_emote_response = await fetch(`https://kitsunes.club/api/emoji?name=${potential_emoji}`);
|
|
|
|
const fetched_emote = await fetched_emote_response.json() as {name: string, url: string};
|
|
|
|
if (typeof fetched_emote.name === "string" && typeof fetched_emote.url === "string") {
|
|
|
|
details.user.emojis[fetched_emote.name] = fetched_emote.url;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
scan_text = scan_text.substring(index_2 + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await Promise.all(emojis_to_get);
|
|
|
|
|
2025-01-22 19:38:42 +01:00
|
|
|
const activity: KitsuclubInfo = {
|
2025-02-28 12:29:54 +01:00
|
|
|
note_id: details.id,
|
|
|
|
user_id: details.user.username,
|
2025-01-22 19:38:42 +01:00
|
|
|
username: details.user.name,
|
|
|
|
avatar: details.user.avatarUrl,
|
|
|
|
emojis: details.user.emojis,
|
|
|
|
text: details.text,
|
2025-02-28 12:29:54 +01:00
|
|
|
date: details.createdAt,
|
|
|
|
images: details.files.map((f) => {
|
|
|
|
return {url: f.thumbnailUrl, alt: f.comment};
|
|
|
|
})
|
2025-02-16 17:05:02 +01:00
|
|
|
};
|
2025-01-22 19:38:42 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
body: JSON.stringify(activity),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export {handler};
|