mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[mastodon-client] GET /v1/search
This commit is contained in:
parent
5e0c2eb497
commit
947f5ba1e2
@ -11,19 +11,27 @@ import { SearchHelpers } from "@/server/api/mastodon/helpers/search.js";
|
||||
|
||||
export function setupEndpointsSearch(router: Router): void {
|
||||
router.get("/v1/search", async (ctx) => {
|
||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||
const accessTokens = ctx.request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
const body: any = ctx.request.body;
|
||||
try {
|
||||
const query: any = convertPaginationArgsIds(limitToInt(ctx.query));
|
||||
const type = query.type || "";
|
||||
const data = await client.search(query.q, type, query);
|
||||
ctx.body = data.data;
|
||||
const auth = await authenticate(ctx.headers.authorization, null);
|
||||
const user = auth[0] ?? undefined;
|
||||
|
||||
if (!user) {
|
||||
ctx.status = 401;
|
||||
return;
|
||||
}
|
||||
|
||||
const args = normalizeUrlQuery(convertPaginationArgsIds(argsToBools(limitToInt(ctx.query), ['resolve', 'following', 'exclude_unreviewed'])));
|
||||
const cache = UserHelpers.getFreshAccountCache();
|
||||
const result = await SearchHelpers.search(user, args.q, args.type, args.resolve, args.following, args.account_id, args['exclude_unreviewed'], args.max_id, args.min_id, args.limit, args.offset, cache);
|
||||
|
||||
ctx.body = {
|
||||
...convertSearch(result),
|
||||
hashtags: result.hashtags.map(p => p.name),
|
||||
};
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
ctx.status = 401;
|
||||
ctx.body = e.response.data;
|
||||
ctx.status = 400;
|
||||
ctx.body = { error: e.message };
|
||||
}
|
||||
});
|
||||
router.get("/v2/search", async (ctx) => {
|
||||
|
Loading…
Reference in New Issue
Block a user