mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
Implement actor endpoint
This commit is contained in:
parent
c573052450
commit
fa3ed293f4
|
|
@ -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",
|
||||
|
|
|
|||
36
server/api/@[username]/actor/index.ts
Normal file
36
server/api/@[username]/actor/index.ts
Normal 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`,
|
||||
})
|
||||
);
|
||||
};
|
||||
24
server/api/@[username]/inbox/index.ts
Normal file
24
server/api/@[username]/inbox/index.ts
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
Loading…
Reference in a new issue