mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Begin more work
This commit is contained in:
parent
1a1bee83a7
commit
dacbc5a00b
6 changed files with 198 additions and 14 deletions
|
|
@ -144,6 +144,29 @@ export default async (
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "Follow" as APFollow: {
|
||||
// Body is an APFollow object
|
||||
// Add the actor to the object actor's followers list
|
||||
|
||||
const user = await User.getByActorId(
|
||||
(body.actor as APActor).id ?? ""
|
||||
);
|
||||
|
||||
if (!user) {
|
||||
return errorResponse("User not found", 404);
|
||||
}
|
||||
|
||||
const actor = await RawActor.addIfNotExists(body.actor as APActor);
|
||||
|
||||
if (actor instanceof Response) {
|
||||
return actor;
|
||||
}
|
||||
|
||||
user.followers.push(actor);
|
||||
|
||||
await user.save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResponse({});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { getUserByToken } from "@auth";
|
||||
import { errorResponse, jsonResponse } from "@response";
|
||||
import { MatchedRoute } from "bun";
|
||||
import { User } from "~database/entities/User";
|
||||
import { RawActor } from "~database/entities/RawActor";
|
||||
|
||||
/**
|
||||
* Fetch a user
|
||||
|
|
@ -11,11 +12,17 @@ export default async (
|
|||
): Promise<Response> => {
|
||||
const id = matchedRoute.params.id;
|
||||
|
||||
const user = await User.findOneBy({
|
||||
// Check auth token
|
||||
const token = req.headers.get("Authorization")?.split(" ")[1] || null;
|
||||
const user = await getUserByToken(token);
|
||||
|
||||
const foundUser = await RawActor.findOneBy({
|
||||
id,
|
||||
});
|
||||
|
||||
if (!user) return errorResponse("User not found", 404);
|
||||
if (!foundUser) return errorResponse("User not found", 404);
|
||||
|
||||
return jsonResponse(user.toAPI());
|
||||
return jsonResponse(
|
||||
await foundUser.toAPIAccount(user?.id === foundUser.id)
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -147,11 +147,11 @@ export default async (req: Request): Promise<Response> => {
|
|||
|
||||
// TODO: Check if locale is valid
|
||||
|
||||
const newUser = new User();
|
||||
|
||||
newUser.username = body.username ?? "";
|
||||
newUser.email = body.email ?? "";
|
||||
newUser.password = await Bun.password.hash(body.password ?? "");
|
||||
await User.createNew({
|
||||
username: body.username ?? "",
|
||||
password: body.password ?? "",
|
||||
email: body.email ?? "",
|
||||
});
|
||||
|
||||
// TODO: Return access token
|
||||
return new Response();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue