More improvements to Webfinger/ActivityPub profile
This commit is contained in:
parent
258abeb13a
commit
d4d10af972
1240
pnpm-lock.yaml
1240
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,10 @@
|
||||
import {Controller, ErrorWithContext, http, HTTPStatus, Injectable, json} from '@extollo/lib'
|
||||
import {Controller, ErrorWithContext, http, HTTPStatus, Inject, Injectable, json, Routing} from '@extollo/lib'
|
||||
import {User} from '../../../models/User.model'
|
||||
|
||||
@Injectable()
|
||||
export class Webfinger extends Controller {
|
||||
@Inject()
|
||||
protected readonly routing!: Routing
|
||||
|
||||
async getUser() {
|
||||
const username = this.request.safe('username').string()
|
||||
@ -20,12 +22,13 @@ export class Webfinger extends Controller {
|
||||
}
|
||||
|
||||
async getWebfinger() {
|
||||
const host = new URL(this.routing.getAppUrl().toRemote).host
|
||||
const resource = this.request.safe('resource').string()
|
||||
if ( !resource.startsWith('acct:') || !resource.endsWith('@garrettmills.dev') ) { // fixme
|
||||
if ( !resource.startsWith('acct:') || !resource.endsWith(`@${host}`) ) {
|
||||
throw new ErrorWithContext('Invalid webfinger resource query', { resource })
|
||||
}
|
||||
|
||||
const username = resource.slice('acct:'.length, -('@garrettmills.dev'.length)) // fixme
|
||||
const username = resource.slice('acct:'.length, -(`@${host}`.length))
|
||||
// @ts-ignore
|
||||
const user = await User.query<User>()
|
||||
.where('username', '=', username)
|
||||
|
@ -29,7 +29,7 @@ export class PageView extends Middleware {
|
||||
view.ip = `${this.request.address.address}:${this.request.address.port}`
|
||||
view.method = this.request.method
|
||||
view.endpoint = this.request.path
|
||||
view.userId = user ? Number(user.getIdentifier()) : undefined
|
||||
view.userId = user ? (user as any).userId : undefined
|
||||
view.xhr = this.request.isXHR
|
||||
|
||||
this.logging.debug(this.request)
|
||||
|
@ -1,22 +1,33 @@
|
||||
import {Maybe, ModelBuilder, ORMUser, Related} from '@extollo/lib'
|
||||
import {Inject, Injectable, Maybe, ModelBuilder, ORMUser, Related, Routing} from '@extollo/lib'
|
||||
import {Pub} from '../../pub/types'
|
||||
import {Certificate} from './pub/Certificate.model'
|
||||
import * as child_process from 'child_process'
|
||||
|
||||
@Injectable()
|
||||
export class User extends ORMUser {
|
||||
@Inject()
|
||||
protected readonly routing!: Routing
|
||||
|
||||
get pubUrl(): string {
|
||||
return `https://garrettmills.dev/pub/${this.username}`
|
||||
return `${this.routing.getAppUrl().toRemote}/pub/${this.username}`
|
||||
}
|
||||
|
||||
async toWebfinger(): Promise<Pub.Webfinger> {
|
||||
const host = new URL(this.routing.getAppUrl().toRemote).host
|
||||
return {
|
||||
subject: `acct:${this.username}@garrettmills.dev`, // fixme
|
||||
subject: `acct:${this.username}@${host}`,
|
||||
aliases: [],
|
||||
links: [
|
||||
{
|
||||
rel: 'self',
|
||||
type: 'application/activity+json',
|
||||
href: this.pubUrl,
|
||||
},
|
||||
{
|
||||
rel: 'http://webfinger.net/rel/profile-page',
|
||||
type: 'text/html',
|
||||
href: `${this.pubUrl}/web`,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
@ -29,7 +40,15 @@ export class User extends ORMUser {
|
||||
],
|
||||
id: this.pubUrl,
|
||||
type: 'Person',
|
||||
name: `${this.firstName ? this.firstName + ' ' : ''}${this.lastName || ''}`.trim() || this.username,
|
||||
url: `${this.pubUrl}/web`,
|
||||
discoverable: true,
|
||||
indexable: false,
|
||||
published: '2023-11-06T00:00:00.000Z', // FIXME
|
||||
// icon: '', // FIXME
|
||||
// image: '', // FIXME
|
||||
preferredUsername: this.username,
|
||||
manuallyApprovesFollowers: false,
|
||||
inbox: `${this.pubUrl}/inbox`,
|
||||
publicKey: {
|
||||
id: `${this.pubUrl}#main-key`,
|
||||
|
@ -14,10 +14,18 @@ export namespace Pub {
|
||||
export interface Actor extends Object {
|
||||
["@context"]: [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1"
|
||||
"https://w3id.org/security/v1",
|
||||
],
|
||||
type: 'Person',
|
||||
name: string,
|
||||
url: string,
|
||||
icon?: string,
|
||||
image?: string,
|
||||
discoverable: boolean,
|
||||
preferredUsername: string,
|
||||
manuallyApprovesFollowers: boolean,
|
||||
indexable: boolean,
|
||||
published: string,
|
||||
inbox: string,
|
||||
publicKey: {
|
||||
id: string,
|
||||
@ -34,6 +42,7 @@ export namespace Pub {
|
||||
|
||||
export interface Webfinger {
|
||||
subject: string,
|
||||
aliases: string[],
|
||||
links: Link[],
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user