add: search endpoints to masto api

This commit is contained in:
Mar0xy 2023-09-24 04:25:01 +02:00
parent 72ff1ffc9d
commit bb2d4b0e09
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
2 changed files with 191 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import { MetaService } from '@/core/MetaService.js';
import multer from 'fastify-multer';
import { apiAuthMastodon } from './endpoints/auth.js';
import { apiAccountMastodon } from './endpoints/account.js';
import { apiSearchMastodon } from './endpoints/search.js';
const staticAssets = fileURLToPath(new URL('../../../../assets/', import.meta.url));
@ -549,6 +550,64 @@ export class MastodonApiServerService {
reply.code(401).send(e.response.data);
}
});
//#endregion
//#region Search
fastify.get("/v1/search", async (_request, reply) => {
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
const accessTokens = _request.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const search = new apiSearchMastodon(_request, client, BASE_URL);
reply.send(await search.SearchV1());
} catch (e: any) {
console.error(e);
console.error(e.response.data);
reply.code(401).send(e.response.data);
}
});
fastify.get("/v2/search", async (_request, reply) => {
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
const accessTokens = _request.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const search = new apiSearchMastodon(_request, client, BASE_URL);
reply.send(await search.SearchV2());
} catch (e: any) {
console.error(e);
console.error(e.response.data);
reply.code(401).send(e.response.data);
}
});
fastify.get("/v1/trends/statuses", async (_request, reply) => {
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
const accessTokens = _request.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const search = new apiSearchMastodon(_request, client, BASE_URL);
reply.send(await search.getStatusTrends());
} catch (e: any) {
console.error(e);
console.error(e.response.data);
reply.code(401).send(e.response.data);
}
});
fastify.get("/v2/suggestions", async (_request, reply) => {
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
const accessTokens = _request.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const search = new apiSearchMastodon(_request, client, BASE_URL);
reply.send(await search.getSuggestions());
} catch (e: any) {
console.error(e);
console.error(e.response.data);
reply.code(401).send(e.response.data);
}
});
//#endregion
done();
}