summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-08-14 18:09:31 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-08-14 18:09:31 +1000
commit110efb3de2e51ae17906cae006d7449d4784c046 (patch)
tree9339adda7557cac63b48b1ee8ffb480d6a2030dc /src
parentcontent type (diff)
downloadserver-110efb3de2e51ae17906cae006d7449d4784c046.tar.xz
more fuckery
Diffstat (limited to 'src')
-rw-r--r--src/activitypub/Server.ts4
-rw-r--r--src/activitypub/routes/user.ts29
-rw-r--r--src/activitypub/well-known/host-meta.ts20
-rw-r--r--src/activitypub/well-known/webfinger.ts (renamed from src/activitypub/webfinger/index.ts)4
-rw-r--r--src/util/entities/Channel.ts2
-rw-r--r--src/util/entities/User.ts25
-rw-r--r--src/util/schemas/responses/WebfingerResponse.ts2
7 files changed, 55 insertions, 31 deletions
diff --git a/src/activitypub/Server.ts b/src/activitypub/Server.ts

index c497d2e6..373d7390 100644 --- a/src/activitypub/Server.ts +++ b/src/activitypub/Server.ts
@@ -8,7 +8,8 @@ import { import { Request, Response, Router } from "express"; import { Server, ServerOptions } from "lambert-server"; import path from "path"; -import webfinger from "./webfinger"; +import hostMeta from "./well-known/host-meta"; +import webfinger from "./well-known/webfinger"; export class APServer extends Server { public declare options: ServerOptions; @@ -63,6 +64,7 @@ export class APServer extends Server { }); this.app.use("/.well-known/webfinger", webfinger); + this.app.use("/.well-known/host-meta", hostMeta); this.app.use(ErrorHandler); diff --git a/src/activitypub/routes/user.ts b/src/activitypub/routes/user.ts
index 3366d711..d68df4d1 100644 --- a/src/activitypub/routes/user.ts +++ b/src/activitypub/routes/user.ts
@@ -1,6 +1,5 @@ import { route } from "@spacebar/api"; -import { Config, User } from "@spacebar/util"; -import { APPerson } from "activitypub-types"; +import { User } from "@spacebar/util"; import { Request, Response, Router } from "express"; const router = Router(); @@ -11,29 +10,5 @@ router.get("/:id", route({}), async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id } }); - const { webDomain } = Config.get().federation; - - const ret: APPerson = { - "@context": "https://www.w3.org/ns/activitystreams", - type: "Person", - id: `https://${webDomain}/fed/user/${user.id}`, - name: user.username, - preferredUsername: user.username, - summary: user.bio, - icon: user.avatar - ? [ - `${Config.get().cdn.endpointPublic}/avatars/${user.id}/${ - user.avatar - }`, - ] - : undefined, - - inbox: `https://${webDomain}/fed/user/${user.id}/inbox`, - outbox: `https://${webDomain}/fed/user/${user.id}/outbox`, - followers: `https://${webDomain}/fed/user/${user.id}/followers`, - following: `https://${webDomain}/fed/user/${user.id}/following`, - liked: `https://${webDomain}/fed/user/${user.id}/likeds`, - }; - - return res.json(ret); + return res.json(user.toAP()); }); diff --git a/src/activitypub/well-known/host-meta.ts b/src/activitypub/well-known/host-meta.ts new file mode 100644
index 00000000..2de2014c --- /dev/null +++ b/src/activitypub/well-known/host-meta.ts
@@ -0,0 +1,20 @@ +import { route } from "@spacebar/api"; +import { Config } from "@spacebar/util"; +import { Request, Response, Router } from "express"; + +const router = Router(); +export default router; + +router.get("/", route({}), async (req: Request, res: Response) => { + res.setHeader("Content-Type", "application/xrd+xml"); + + const { webDomain } = Config.get().federation; + + const ret = `<?xml version="1.0" encoding="UTF-8"?> + <XRD + xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"> + <Link rel="lrdd" type="application/xrd+xml" template="https://${webDomain}/.well-known/webfinger?resource={uri}"/> + </XRD>`; + + return res.send(ret); +}); diff --git a/src/activitypub/webfinger/index.ts b/src/activitypub/well-known/webfinger.ts
index f1b49624..c24a1477 100644 --- a/src/activitypub/webfinger/index.ts +++ b/src/activitypub/well-known/webfinger.ts
@@ -58,6 +58,10 @@ router.get( type: "application/activity+json", href: `https://${webDomain}/fed/${type}/${resourceId}`, }, + // { + // rel: "http://ostatus.org/schema/1.0/subscribe", + // href: `"https://${webDomain}/fed/authorize-follow?acct={uri}"`, + // }, ], }); }, diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 93265d07..33528d90 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts
@@ -500,8 +500,6 @@ export class Channel extends BaseClass { inbox: `https://${webDomain}/fed/channel/${this.id}/inbox`, outbox: `https://${webDomain}/fed/channel/${this.id}/outbox`, followers: `https://${webDomain}/fed/channel/${this.id}/followers`, - following: `https://${webDomain}/fed/channel/${this.id}/following`, - liked: `https://${webDomain}/fed/channel/${this.id}/likeds`, }; } } diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index c6582b00..4263d39d 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts
@@ -16,6 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { APPerson } from "activitypub-types"; import { Request } from "express"; import { Column, @@ -271,6 +272,30 @@ export class User extends BaseClass { return user as UserPrivate; } + toAP(): APPerson { + const { webDomain } = Config.get().federation; + + return { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Person", + id: `https://${webDomain}/fed/user/${user.id}`, + name: this.username, + preferredUsername: this.username, + summary: this.bio, + icon: this.avatar + ? [ + `${Config.get().cdn.endpointPublic}/avatars/${ + this.id + }/${this.avatar}`, + ] + : undefined, + + inbox: `https://${webDomain}/fed/user/${this.id}/inbox`, + outbox: `https://${webDomain}/fed/user/${this.id}/outbox`, + followers: `https://${webDomain}/fed/user/${this.id}/followers`, + }; + } + static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) { return await User.findOneOrFail({ where: { id: user_id }, diff --git a/src/util/schemas/responses/WebfingerResponse.ts b/src/util/schemas/responses/WebfingerResponse.ts
index a3186a03..6b0ab0f9 100644 --- a/src/util/schemas/responses/WebfingerResponse.ts +++ b/src/util/schemas/responses/WebfingerResponse.ts
@@ -1,6 +1,6 @@ interface WebfingerLink { rel: string; - type: string; + type?: string; href: string; template?: string; }