Implement actor endpoint

This commit is contained in:
Jesse Wierzbinski 2023-09-12 10:53:30 -10:00
parent c573052450
commit fa3ed293f4
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
4 changed files with 61 additions and 0 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -3,6 +3,7 @@
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/jsonld": "^1.5.9",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"activitypub-types": "^1.0.3",

View file

@ -0,0 +1,36 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { User } from "~database/entities/User";
import { getHost } from "@config";
import { compact } from "jsonld";
/**
* ActivityPub user actor endpoinmt
*/
export default async (
req: Request,
matchedRoute: MatchedRoute
): Promise<Response> => {
// In the format acct:name@example.com
const username = matchedRoute.params.username;
const user = await User.findOneBy({ username });
if (!user) {
return errorResponse("User not found", 404);
}
return jsonResponse(
await compact({
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
],
id: `${getHost()}/@${user.username}/actor`,
type: "Person",
preferredUsername: user.username,
summary: user.bio,
inbox: `${getHost()}/@${user.username}/inbox`,
})
);
};

View file

@ -0,0 +1,24 @@
import { errorResponse, jsonResponse } from "@response";
import { MatchedRoute } from "bun";
import { User } from "~database/entities/User";
import { getHost } from "@config";
import { compact } from "jsonld";
/**
* ActivityPub user actor endpoinmt
*/
export default async (
req: Request,
matchedRoute: MatchedRoute
): Promise<Response> => {
// In the format acct:name@example.com
const username = matchedRoute.params.username;
const user = await User.findOneBy({ username });
if (!user) {
return errorResponse("User not found", 404);
}
};