mirror of
https://git.joinfirefish.org/firefish/firefish.git
synced 2024-05-19 21:51:11 +02:00
f5cd9449e9
revert fix: some Masotdon API compat issues (#9592) Co-authored-by: GeopJr <geopjr@noreply.codeberg.org> Co-committed-by: GeopJr <geopjr@noreply.codeberg.org>
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import megalodon, { MegalodonInterface } from '@cutls/megalodon';
|
|
import Router from "@koa/router";
|
|
import { koaBody } from 'koa-body';
|
|
import { getClient } from '../ApiMastodonCompatibleService.js';
|
|
|
|
export function apiFilterMastodon(router: Router): void {
|
|
|
|
router.get('/v1/filters', 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 data = await client.getFilters();
|
|
ctx.body = data.data;
|
|
} catch (e: any) {
|
|
console.error(e)
|
|
ctx.status = 401;
|
|
ctx.body = e.response.data;
|
|
}
|
|
});
|
|
|
|
router.get('/v1/filters/:id', 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 data = await client.getFilter(ctx.params.id);
|
|
ctx.body = data.data;
|
|
} catch (e: any) {
|
|
console.error(e)
|
|
ctx.status = 401;
|
|
ctx.body = e.response.data;
|
|
}
|
|
});
|
|
|
|
router.post('/v1/filters', 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 data = await client.createFilter(body.phrase, body.context, body);
|
|
ctx.body = data.data;
|
|
} catch (e: any) {
|
|
console.error(e)
|
|
ctx.status = 401;
|
|
ctx.body = e.response.data;
|
|
}
|
|
});
|
|
|
|
router.post('/v1/filters/:id', 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 data = await client.updateFilter(ctx.params.id, body.phrase, body.context);
|
|
ctx.body = data.data;
|
|
} catch (e: any) {
|
|
console.error(e)
|
|
ctx.status = 401;
|
|
ctx.body = e.response.data;
|
|
}
|
|
});
|
|
|
|
router.delete('/v1/filters/:id', 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 data = await client.deleteFilter(ctx.params.id);
|
|
ctx.body = data.data;
|
|
} catch (e: any) {
|
|
console.error(e)
|
|
ctx.status = 401;
|
|
ctx.body = e.response.data;
|
|
}
|
|
});
|
|
|
|
}
|