mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { apiRoute, applyConfig, auth, handleZodError } from "@/api";
|
|
import { zValidator } from "@hono/zod-validator";
|
|
import { z } from "zod";
|
|
import { RolePermissions } from "~/drizzle/schema";
|
|
import { Relationship } from "~/packages/database-interface/relationship";
|
|
import { User } from "~/packages/database-interface/user";
|
|
|
|
export const meta = applyConfig({
|
|
allowedMethods: ["POST"],
|
|
ratelimits: {
|
|
max: 30,
|
|
duration: 60,
|
|
},
|
|
route: "/api/v1/accounts/:id/unmute",
|
|
auth: {
|
|
required: true,
|
|
oauthPermissions: ["write:mutes"],
|
|
},
|
|
permissions: {
|
|
required: [
|
|
RolePermissions.ManageOwnMutes,
|
|
RolePermissions.ViewAccounts,
|
|
],
|
|
},
|
|
});
|
|
|
|
export const schemas = {
|
|
param: z.object({
|
|
id: z.string().uuid(),
|
|
}),
|
|
};
|
|
|
|
export default apiRoute((app) =>
|
|
app.on(
|
|
meta.allowedMethods,
|
|
meta.route,
|
|
zValidator("param", schemas.param, handleZodError),
|
|
auth(meta.auth, meta.permissions),
|
|
async (context) => {
|
|
const { id } = context.req.valid("param");
|
|
const { user: self } = context.req.valid("header");
|
|
|
|
if (!self) {
|
|
return context.json({ error: "Unauthorized" }, 401);
|
|
}
|
|
|
|
const user = await User.fromId(id);
|
|
|
|
if (!user) {
|
|
return context.json({ error: "User not found" }, 404);
|
|
}
|
|
|
|
const foundRelationship = await Relationship.fromOwnerAndSubject(
|
|
self,
|
|
user,
|
|
);
|
|
|
|
if (foundRelationship.data.muting) {
|
|
await foundRelationship.update({
|
|
muting: false,
|
|
mutingNotifications: false,
|
|
});
|
|
}
|
|
|
|
return context.json(foundRelationship.toApi());
|
|
},
|
|
),
|
|
);
|