add: filter endpoint to masto api
This commit is contained in:
parent
4e375f303f
commit
34e6717dab
2 changed files with 125 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ import { apiAuthMastodon } from './endpoints/auth.js';
|
|||
import { apiAccountMastodon } from './endpoints/account.js';
|
||||
import { apiSearchMastodon } from './endpoints/search.js';
|
||||
import { apiNotifyMastodon } from './endpoints/notifications.js';
|
||||
import { apiFilterMastodon } from './endpoints/filter.js';
|
||||
|
||||
const staticAssets = fileURLToPath(new URL('../../../../assets/', import.meta.url));
|
||||
|
||||
|
|
@ -667,6 +668,64 @@ export class MastodonApiServerService {
|
|||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region Filters
|
||||
fastify.get<{ Params: { id: string } }>("/v1/filters/:id", async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
const accessTokens = _request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const filter = new apiFilterMastodon(_request, client);
|
||||
!_request.params.id ? reply.send(await filter.getFilters()) : reply.send(await filter.getFilter());
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
|
||||
fastify.post("/v1/filters", async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
const accessTokens = _request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const filter = new apiFilterMastodon(_request, client);
|
||||
reply.send(await filter.createFilter());
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
|
||||
fastify.post<{ Params: { id: string } }>("/v1/filters/:id", async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
const accessTokens = _request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const filter = new apiFilterMastodon(_request, client);
|
||||
reply.send(await filter.updateFilter());
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
|
||||
fastify.delete<{ Params: { id: string } }>("/v1/filters/:id", async (_request, reply) => {
|
||||
const BASE_URL = `${_request.protocol}://${_request.hostname}`;
|
||||
const accessTokens = _request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const filter = new apiFilterMastodon(_request, client);
|
||||
reply.send(await filter.rmFilter());
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
reply.code(401).send(e.response.data);
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
done();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue