mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
guh
This commit is contained in:
parent
d0c07d804b
commit
2cadb68a56
6 changed files with 332 additions and 97 deletions
57
server/api/api/v1/statuses/[id]/index.ts
Normal file
57
server/api/api/v1/statuses/[id]/index.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { getUserByToken } from "@auth";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { RawObject } from "~database/entities/RawObject";
|
||||
import { Status } from "~database/entities/Status";
|
||||
|
||||
/**
|
||||
* Fetch a user
|
||||
*/
|
||||
export default async (
|
||||
req: Request,
|
||||
matchedRoute: MatchedRoute
|
||||
): Promise<Response> => {
|
||||
const id = matchedRoute.params.id;
|
||||
|
||||
// Check auth token
|
||||
const token = req.headers.get("Authorization")?.split(" ")[1] || null;
|
||||
const user = await getUserByToken(token);
|
||||
|
||||
// TODO: Add checks for user's permissions to view this status
|
||||
|
||||
let foundStatus: RawObject | null;
|
||||
try {
|
||||
foundStatus = await RawObject.findOneBy({
|
||||
id,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResponse("Invalid ID", 404);
|
||||
}
|
||||
|
||||
if (!foundStatus) return errorResponse("Record not found", 404);
|
||||
|
||||
if (req.method === "GET") {
|
||||
return jsonResponse(await foundStatus.toAPI());
|
||||
} else if (req.method === "DELETE") {
|
||||
if ((await foundStatus.toAPI()).account.id !== user?.id) {
|
||||
return errorResponse("Unauthorized", 401);
|
||||
}
|
||||
|
||||
// Get associated Status object
|
||||
const status = await Status.createQueryBuilder("status")
|
||||
.leftJoinAndSelect("status.object", "object")
|
||||
.where("object.id = :id", { id: foundStatus.id })
|
||||
.getOne();
|
||||
|
||||
if (!status) {
|
||||
return errorResponse("Status not found", 404);
|
||||
}
|
||||
|
||||
// Delete status and all associated objects
|
||||
await status.object.remove();
|
||||
|
||||
return jsonResponse({});
|
||||
}
|
||||
|
||||
return jsonResponse({});
|
||||
};
|
||||
|
|
@ -53,8 +53,12 @@ export default async (req: Request): Promise<Response> => {
|
|||
visibility?: "public" | "unlisted" | "private" | "direct";
|
||||
language?: string;
|
||||
scheduled_at?: string;
|
||||
local_only?: boolean;
|
||||
content_type?: string;
|
||||
}>(req);
|
||||
|
||||
// TODO: Parse Markdown statuses
|
||||
|
||||
// Validate status
|
||||
if (!status) {
|
||||
return errorResponse("Status is required", 422);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue