2023-02-09 23:21:50 +01:00
|
|
|
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";
|
2023-10-05 20:22:02 +02:00
|
|
|
import { auth } from "@/server/api/mastodon/middleware/auth.js";
|
2023-02-09 23:21:50 +01:00
|
|
|
|
2023-09-29 21:45:58 +02:00
|
|
|
export function setupEndpointsSearch(router: Router): void {
|
2023-10-05 20:22:02 +02:00
|
|
|
router.get(["/v1/search", "/v2/search"],
|
|
|
|
auth(true, ['read:search']),
|
|
|
|
async (ctx) => {
|
2023-10-01 17:52:59 +02:00
|
|
|
const args = normalizeUrlQuery(convertPaginationArgsIds(argsToBools(limitToInt(ctx.query), ['resolve', 'following', 'exclude_unreviewed'])));
|
2023-10-07 21:39:22 +02:00
|
|
|
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
|
|
|
|
2023-10-05 20:22:02 +02:00
|
|
|
ctx.body = convertSearchIds(result);
|
2023-07-08 03:24:11 +02:00
|
|
|
|
2023-10-05 20:22:02 +02:00
|
|
|
if (ctx.path === "/v1/search") {
|
|
|
|
ctx.body = {
|
|
|
|
...ctx.body,
|
|
|
|
hashtags: result.hashtags.map(p => p.name),
|
|
|
|
};
|
2023-10-01 17:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-05 20:22:02 +02:00
|
|
|
);
|
2023-10-05 01:38:18 +02:00
|
|
|
}
|