mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
[mastodon-client] Make filter endpoints refer to web frontend
This commit is contained in:
parent
f5e28fc27a
commit
059a20f4b1
3 changed files with 6 additions and 106 deletions
|
@ -19,10 +19,6 @@ export function convertAttachmentId(attachment: MastodonEntity.Attachment) {
|
||||||
return simpleConvertId(attachment);
|
return simpleConvertId(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertFilterId(filter: MastodonEntity.Filter) {
|
|
||||||
return simpleConvertId(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function convertListId(list: MastodonEntity.List) {
|
export function convertListId(list: MastodonEntity.List) {
|
||||||
return simpleConvertId(list);
|
return simpleConvertId(list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,89 +1,11 @@
|
||||||
import Router from "@koa/router";
|
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 {
|
export function setupEndpointsFilter(router: Router): void {
|
||||||
router.get("/v1/filters", async (ctx) => {
|
router.get(["/v1/filters", "/v2/filters"], async (ctx) => {
|
||||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
ctx.body = [];
|
||||||
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.post(["/v1/filters", "/v2/filters"], async (ctx) => {
|
||||||
router.get("/v1/filters/:id", async (ctx) => {
|
ctx.status = 400;
|
||||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
ctx.body = { error: "Please change word mute settings in the web frontend settings." };
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import Router from "@koa/router";
|
import Router from "@koa/router";
|
||||||
import { getClient } from "@/server/api/mastodon/index.js";
|
import { getClient } from "@/server/api/mastodon/index.js";
|
||||||
import { convertId, IdType } from "@/misc/convert-id.js";
|
import { convertId, IdType } from "@/misc/convert-id.js";
|
||||||
import { convertAccountId, convertAnnouncementId, convertFilterId } from "@/server/api/mastodon/converters.js";
|
import { convertAnnouncementId } 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 { MiscHelpers } from "@/server/api/mastodon/helpers/misc.js";
|
import { MiscHelpers } from "@/server/api/mastodon/helpers/misc.js";
|
||||||
|
|
||||||
export function setupEndpointsMisc(router: Router): void {
|
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) => {
|
router.get("/v1/trends", async (ctx) => {
|
||||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||||
const accessTokens = ctx.request.headers.authorization;
|
const accessTokens = ctx.request.headers.authorization;
|
||||||
|
|
Loading…
Reference in a new issue