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'
|
import {User} from '../../../models/User.model'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Webfinger extends Controller {
|
export class Webfinger extends Controller {
|
||||||
|
@Inject()
|
||||||
|
protected readonly routing!: Routing
|
||||||
|
|
||||||
async getUser() {
|
async getUser() {
|
||||||
const username = this.request.safe('username').string()
|
const username = this.request.safe('username').string()
|
||||||
@ -20,12 +22,13 @@ export class Webfinger extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getWebfinger() {
|
async getWebfinger() {
|
||||||
|
const host = new URL(this.routing.getAppUrl().toRemote).host
|
||||||
const resource = this.request.safe('resource').string()
|
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 })
|
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
|
// @ts-ignore
|
||||||
const user = await User.query<User>()
|
const user = await User.query<User>()
|
||||||
.where('username', '=', username)
|
.where('username', '=', username)
|
||||||
|
@ -29,7 +29,7 @@ export class PageView extends Middleware {
|
|||||||
view.ip = `${this.request.address.address}:${this.request.address.port}`
|
view.ip = `${this.request.address.address}:${this.request.address.port}`
|
||||||
view.method = this.request.method
|
view.method = this.request.method
|
||||||
view.endpoint = this.request.path
|
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
|
view.xhr = this.request.isXHR
|
||||||
|
|
||||||
this.logging.debug(this.request)
|
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 {Pub} from '../../pub/types'
|
||||||
import {Certificate} from './pub/Certificate.model'
|
import {Certificate} from './pub/Certificate.model'
|
||||||
import * as child_process from 'child_process'
|
import * as child_process from 'child_process'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class User extends ORMUser {
|
export class User extends ORMUser {
|
||||||
|
@Inject()
|
||||||
|
protected readonly routing!: Routing
|
||||||
|
|
||||||
get pubUrl(): string {
|
get pubUrl(): string {
|
||||||
return `https://garrettmills.dev/pub/${this.username}`
|
return `${this.routing.getAppUrl().toRemote}/pub/${this.username}`
|
||||||
}
|
}
|
||||||
|
|
||||||
async toWebfinger(): Promise<Pub.Webfinger> {
|
async toWebfinger(): Promise<Pub.Webfinger> {
|
||||||
|
const host = new URL(this.routing.getAppUrl().toRemote).host
|
||||||
return {
|
return {
|
||||||
subject: `acct:${this.username}@garrettmills.dev`, // fixme
|
subject: `acct:${this.username}@${host}`,
|
||||||
|
aliases: [],
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
rel: 'self',
|
rel: 'self',
|
||||||
type: 'application/activity+json',
|
type: 'application/activity+json',
|
||||||
href: this.pubUrl,
|
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,
|
id: this.pubUrl,
|
||||||
type: 'Person',
|
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,
|
preferredUsername: this.username,
|
||||||
|
manuallyApprovesFollowers: false,
|
||||||
inbox: `${this.pubUrl}/inbox`,
|
inbox: `${this.pubUrl}/inbox`,
|
||||||
publicKey: {
|
publicKey: {
|
||||||
id: `${this.pubUrl}#main-key`,
|
id: `${this.pubUrl}#main-key`,
|
||||||
|
@ -14,10 +14,18 @@ export namespace Pub {
|
|||||||
export interface Actor extends Object {
|
export interface Actor extends Object {
|
||||||
["@context"]: [
|
["@context"]: [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
"https://w3id.org/security/v1"
|
"https://w3id.org/security/v1",
|
||||||
],
|
],
|
||||||
type: 'Person',
|
type: 'Person',
|
||||||
|
name: string,
|
||||||
|
url: string,
|
||||||
|
icon?: string,
|
||||||
|
image?: string,
|
||||||
|
discoverable: boolean,
|
||||||
preferredUsername: string,
|
preferredUsername: string,
|
||||||
|
manuallyApprovesFollowers: boolean,
|
||||||
|
indexable: boolean,
|
||||||
|
published: string,
|
||||||
inbox: string,
|
inbox: string,
|
||||||
publicKey: {
|
publicKey: {
|
||||||
id: string,
|
id: string,
|
||||||
@ -34,6 +42,7 @@ export namespace Pub {
|
|||||||
|
|
||||||
export interface Webfinger {
|
export interface Webfinger {
|
||||||
subject: string,
|
subject: string,
|
||||||
|
aliases: string[],
|
||||||
links: Link[],
|
links: Link[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user