mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import {
|
|
accountNotFound,
|
|
apiRoute,
|
|
auth,
|
|
reusedResponses,
|
|
withUserParam,
|
|
} from "@/api";
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
|
import { Relationship } from "@versia/kit/db";
|
|
import { RolePermissions } from "@versia/kit/tables";
|
|
import { Account as AccountSchema } from "~/classes/schemas/account";
|
|
import { Relationship as RelationshipSchema } from "~/classes/schemas/relationship";
|
|
|
|
const route = createRoute({
|
|
method: "post",
|
|
path: "/api/v1/accounts/{id}/remove_from_followers",
|
|
summary: "Remove account from followers",
|
|
description: "Remove the given account from your followers.",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/methods/accounts/#remove_from_followers",
|
|
},
|
|
tags: ["Accounts"],
|
|
middleware: [
|
|
auth({
|
|
auth: true,
|
|
scopes: ["write:follows"],
|
|
permissions: [
|
|
RolePermissions.ManageOwnFollows,
|
|
RolePermissions.ViewAccounts,
|
|
],
|
|
}),
|
|
withUserParam,
|
|
] as const,
|
|
request: {
|
|
params: z.object({
|
|
id: AccountSchema.shape.id,
|
|
}),
|
|
},
|
|
responses: {
|
|
200: {
|
|
description:
|
|
"Successfully removed from followers, or account was already not following you",
|
|
content: {
|
|
"application/json": {
|
|
schema: RelationshipSchema,
|
|
},
|
|
},
|
|
},
|
|
404: accountNotFound,
|
|
...reusedResponses,
|
|
},
|
|
});
|
|
|
|
export default apiRoute((app) =>
|
|
app.openapi(route, async (context) => {
|
|
const { user } = context.get("auth");
|
|
const otherUser = context.get("user");
|
|
|
|
const oppositeRelationship = await Relationship.fromOwnerAndSubject(
|
|
otherUser,
|
|
user,
|
|
);
|
|
|
|
if (oppositeRelationship.data.following) {
|
|
await oppositeRelationship.update({
|
|
following: false,
|
|
});
|
|
}
|
|
|
|
const foundRelationship = await Relationship.fromOwnerAndSubject(
|
|
user,
|
|
otherUser,
|
|
);
|
|
|
|
return context.json(foundRelationship.toApi(), 200);
|
|
}),
|
|
);
|