[mastodon-client] Make filter endpoints refer to web frontend

This commit is contained in:
Laura Hausmann 2023-10-05 00:08:07 +02:00
parent f5e28fc27a
commit 059a20f4b1
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
3 changed files with 6 additions and 106 deletions

View File

@ -19,10 +19,6 @@ export function convertAttachmentId(attachment: MastodonEntity.Attachment) {
return simpleConvertId(attachment);
}
export function convertFilterId(filter: MastodonEntity.Filter) {
return simpleConvertId(filter);
}
export function convertListId(list: MastodonEntity.List) {
return simpleConvertId(list);
}

View File

@ -1,89 +1,11 @@
import Router from "@koa/router";
import { getClient } from "../index.js";
import { convertId, IdType } from "../../index.js";
import { convertFilterId } from "../converters.js";
export function setupEndpointsFilter(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.map((filter) => convertFilterId(filter));
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
router.get(["/v1/filters", "/v2/filters"], async (ctx) => {
ctx.body = [];
});
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(
convertId(ctx.params.id, IdType.IceshrimpId),
);
ctx.body = convertFilterId(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 = convertFilterId(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(
convertId(ctx.params.id, IdType.IceshrimpId),
body.phrase,
body.context,
);
ctx.body = convertFilterId(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(
convertId(ctx.params.id, IdType.IceshrimpId),
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
router.post(["/v1/filters", "/v2/filters"], async (ctx) => {
ctx.status = 400;
ctx.body = { error: "Please change word mute settings in the web frontend settings." };
});
}

View File

@ -1,10 +1,7 @@
import Router from "@koa/router";
import { getClient } from "@/server/api/mastodon/index.js";
import { convertId, IdType } from "@/misc/convert-id.js";
import { convertAccountId, convertAnnouncementId, convertFilterId } from "@/server/api/mastodon/converters.js";
import { Users } from "@/models/index.js";
import { getInstance } from "@/server/api/mastodon/endpoints/meta.js";
import { IsNull } from "typeorm";
import { convertAnnouncementId } from "@/server/api/mastodon/converters.js";
import { MiscHelpers } from "@/server/api/mastodon/helpers/misc.js";
export function setupEndpointsMisc(router: Router): void {
@ -67,21 +64,6 @@ export function setupEndpointsMisc(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); // we are using this here, because in private mode some info isnt
// displayed without being logged in
try {
const data = await client.getFilters();
ctx.body = data.data.map((filter) => convertFilterId(filter));
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
});
router.get("/v1/trends", async (ctx) => {
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const accessTokens = ctx.request.headers.authorization;