2025-02-14 16:44:32 +01:00
|
|
|
import {
|
|
|
|
|
apiRoute,
|
|
|
|
|
auth,
|
|
|
|
|
noteNotFound,
|
|
|
|
|
reusedResponses,
|
|
|
|
|
withNoteParam,
|
|
|
|
|
} from "@/api";
|
2025-02-05 21:49:39 +01:00
|
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
2024-11-01 21:05:54 +01:00
|
|
|
import { RolePermissions } from "@versia/kit/tables";
|
2024-12-30 18:00:23 +01:00
|
|
|
import { ApiError } from "~/classes/errors/api-error";
|
2025-02-14 16:44:32 +01:00
|
|
|
import { Status as StatusSchema } from "~/classes/schemas/status";
|
2024-05-06 09:16:33 +02:00
|
|
|
|
2024-09-27 13:00:12 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "post",
|
|
|
|
|
path: "/api/v1/statuses/{id}/unpin",
|
2025-02-14 16:44:32 +01:00
|
|
|
summary: "Unpin status from profile",
|
|
|
|
|
description: "Unfeature a status from the top of your profile.",
|
|
|
|
|
externalDocs: {
|
|
|
|
|
url: "https://docs.joinmastodon.org/methods/statuses/#unpin",
|
|
|
|
|
},
|
|
|
|
|
tags: ["Statuses"],
|
2024-12-30 19:18:31 +01:00
|
|
|
middleware: [
|
|
|
|
|
auth({
|
|
|
|
|
auth: true,
|
|
|
|
|
permissions: [
|
|
|
|
|
RolePermissions.ManageOwnNotes,
|
|
|
|
|
RolePermissions.ViewNotes,
|
|
|
|
|
],
|
|
|
|
|
}),
|
2024-12-30 21:30:10 +01:00
|
|
|
withNoteParam,
|
2024-12-30 19:18:31 +01:00
|
|
|
] as const,
|
2024-09-27 13:00:12 +02:00
|
|
|
request: {
|
2024-12-30 20:26:56 +01:00
|
|
|
params: z.object({
|
2025-02-14 16:44:32 +01:00
|
|
|
id: StatusSchema.shape.id,
|
2024-12-30 20:26:56 +01:00
|
|
|
}),
|
2024-09-27 13:00:12 +02:00
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
2025-02-14 16:44:32 +01:00
|
|
|
description: "Status unpinned, or was already not pinned",
|
2024-09-27 13:00:12 +02:00
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
2025-02-14 16:44:32 +01:00
|
|
|
schema: StatusSchema,
|
2024-09-27 13:00:12 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-14 16:44:32 +01:00
|
|
|
404: noteNotFound,
|
|
|
|
|
401: reusedResponses[401],
|
2024-09-27 13:00:12 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-19 20:06:38 +02:00
|
|
|
export default apiRoute((app) =>
|
2024-09-27 13:00:12 +02:00
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
const { user } = context.get("auth");
|
2024-12-30 21:30:10 +01:00
|
|
|
const note = context.get("note");
|
2024-05-06 09:16:33 +02:00
|
|
|
|
2024-12-30 21:30:10 +01:00
|
|
|
if (note.author.id !== user.id) {
|
2024-12-30 18:00:23 +01:00
|
|
|
throw new ApiError(401, "Unauthorized");
|
2024-09-27 13:00:12 +02:00
|
|
|
}
|
2024-05-06 09:16:33 +02:00
|
|
|
|
2024-12-30 21:30:10 +01:00
|
|
|
await user.unpin(note);
|
2024-05-06 09:16:33 +02:00
|
|
|
|
2024-12-30 21:30:10 +01:00
|
|
|
if (!note) {
|
2024-12-30 18:00:23 +01:00
|
|
|
throw new ApiError(404, "Note not found");
|
2024-09-27 13:00:12 +02:00
|
|
|
}
|
2024-05-06 09:16:33 +02:00
|
|
|
|
2024-12-30 21:30:10 +01:00
|
|
|
return context.json(await note.toApi(user), 200);
|
2024-09-27 13:00:12 +02:00
|
|
|
}),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|