diff --git a/bun.lockb b/bun.lockb index d4ae0e9b..bd57f75f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 459dcd8d..5056ff83 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/api/@[username]/actor/index.ts b/server/api/@[username]/actor/index.ts new file mode 100644 index 00000000..35a73426 --- /dev/null +++ b/server/api/@[username]/actor/index.ts @@ -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 => { + // 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`, + }) + ); +}; diff --git a/server/api/@[username]/inbox/index.ts b/server/api/@[username]/inbox/index.ts new file mode 100644 index 00000000..4ef7fca9 --- /dev/null +++ b/server/api/@[username]/inbox/index.ts @@ -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 => { + // 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); + } + + +};