iceshrimp/packages/backend/src/server/api/mastodon/endpoints/search.ts

24 lines
1.1 KiB
TypeScript
Raw Normal View History

import Router from "@koa/router";
2023-09-30 23:57:44 +02:00
import { argsToBools, convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "./timeline.js";
2023-10-05 14:36:14 +02:00
import { convertSearchIds } from "../converters.js";
2023-09-30 23:57:44 +02:00
import { SearchHelpers } from "@/server/api/mastodon/helpers/search.js";
import { auth } from "@/server/api/mastodon/middleware/auth.js";
export function setupEndpointsSearch(router: Router): void {
router.get(["/v1/search", "/v2/search"],
auth(true, ['read:search']),
async (ctx) => {
const args = normalizeUrlQuery(convertPaginationArgsIds(argsToBools(limitToInt(ctx.query), ['resolve', 'following', 'exclude_unreviewed'])));
const result = await SearchHelpers.search(args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, ctx);
2023-10-01 01:30:09 +02:00
ctx.body = convertSearchIds(result);
if (ctx.path === "/v1/search") {
ctx.body = {
...ctx.body,
hashtags: result.hashtags.map(p => p.name),
};
}
}
);
2023-10-05 01:38:18 +02:00
}