Begin more work

This commit is contained in:
Jesse Wierzbinski 2023-09-19 14:16:50 -10:00
parent 1a1bee83a7
commit dacbc5a00b
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
6 changed files with 198 additions and 14 deletions

View file

@ -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({});

View file

@ -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)
);
};

View file

@ -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();