From 1a39e7a48e4dc9c693fe1054d6eb2106b9587854 Mon Sep 17 00:00:00 2001 From: fruye Date: Sun, 23 Apr 2023 22:17:02 +0200 Subject: [PATCH] feat: Implement reading Announcements from MastoAPI --- .../mastodon/ApiMastodonCompatibleService.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts b/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts index 48eeec79cc..5374f5077c 100644 --- a/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts +++ b/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts @@ -62,6 +62,34 @@ export function apiMastodonCompatible(router: Router): void { } }); + router.get("/v1/announcements", async (ctx) => { + const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; + const accessTokens = ctx.request.headers.authorization; + const client = getClient(BASE_URL, accessTokens); + try { + const data = await client.getInstanceAnnouncements(); + ctx.body = data.data; + } catch (e: any) { + console.error(e); + ctx.status = 401; + ctx.body = e.response.data; + } + }); + + router.post<{ Params: { id: string } }>("/v1/announcements/:id/dismiss", async (ctx) => { + const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; + const accessTokens = ctx.request.headers.authorization; + const client = getClient(BASE_URL, accessTokens); + try { + const data = await client.dismissInstanceAnnouncement(ctx.params.id); + ctx.body = data.data; + } catch (e: any) { + console.error(e); + ctx.status = 401; + ctx.body = e.response.data; + } + }); + router.get("/v1/filters", async (ctx) => { const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const accessTokens = ctx.request.headers.authorization;