Files
FrozenFriendsYume/packages/backend/built/server/api/mastodon/endpoints/misc.js
T
2026-07-26 18:25:37 +09:00

58 lines
2.2 KiB
JavaScript

import { MiscHelpers } from "../helpers/misc.js";
import { argsToBools, limitToInt } from "./timeline.js";
import { Announcements } from "../../../../models/index.js";
import { auth } from "../middleware/auth.js";
import { MastoApiError } from "../middleware/catch-errors.js";
import { filterContext } from "../middleware/filter-context.js";
export function setupEndpointsMisc(router) {
router.get("/v1/custom_emojis", async (ctx)=>{
ctx.body = await MiscHelpers.getCustomEmoji();
});
router.get("/v1/instance", async (ctx)=>{
ctx.body = await MiscHelpers.getInstance(ctx);
});
router.get("/v1/announcements", auth(true), async (ctx)=>{
const args = argsToBools(ctx.query, [
'with_dismissed'
]);
ctx.body = await MiscHelpers.getAnnouncements(args['with_dismissed'], ctx);
});
router.post("/v1/announcements/:id/dismiss", auth(true, [
'write:accounts'
]), async (ctx)=>{
const announcement = await Announcements.findOneBy({
id: ctx.params.id
});
if (!announcement) throw new MastoApiError(404);
await MiscHelpers.dismissAnnouncement(announcement, ctx);
ctx.body = {};
});
//FIXME: add link pagination to trends (ref: https://mastodon.social/api/v1/trends/tags?offset=10&limit=1)
router.get([
"/v1/trends/tags",
"/v1/trends"
], async (ctx)=>{
const args = limitToInt(ctx.query);
ctx.body = await MiscHelpers.getTrendingHashtags(args.limit, args.offset);
//FIXME: convert ids
});
router.get("/v1/trends/statuses", filterContext('public'), async (ctx)=>{
const args = limitToInt(ctx.query);
ctx.body = await MiscHelpers.getTrendingStatuses(args.limit, args.offset, ctx);
});
router.get("/v1/trends/links", async (ctx)=>{
ctx.body = [];
});
router.get("/v1/preferences", auth(true, [
'read:accounts'
]), async (ctx)=>{
ctx.body = await MiscHelpers.getPreferences(ctx);
});
router.get("/v2/suggestions", auth(true, [
'read:accounts'
]), async (ctx)=>{
const args = limitToInt(ctx.query);
ctx.body = await MiscHelpers.getFollowSuggestions(args.limit, ctx);
});
}