You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
import {Controller, ErrorWithContext, http, HTTPStatus, Injectable, json} from '@extollo/lib'
|
|
import {User} from '../../../models/User.model'
|
|
|
|
@Injectable()
|
|
export class Webfinger extends Controller {
|
|
|
|
async getUser() {
|
|
const username = this.request.safe('username').string()
|
|
|
|
// @ts-ignore
|
|
const user = await User.query<User>()
|
|
.where('username', '=', username)
|
|
.first()
|
|
|
|
if ( !user ) {
|
|
return http(HTTPStatus.NOT_FOUND)
|
|
}
|
|
|
|
return json(await user.toPub())
|
|
}
|
|
|
|
async getWebfinger() {
|
|
const resource = this.request.safe('resource').string()
|
|
if ( !resource.startsWith('acct:') || !resource.endsWith('@garrettmills.dev') ) { // fixme
|
|
throw new ErrorWithContext('Invalid webfinger resource query', { resource })
|
|
}
|
|
|
|
const username = resource.slice('acct:'.length, -('@garrettmills.dev'.length)) // fixme
|
|
// @ts-ignore
|
|
const user = await User.query<User>()
|
|
.where('username', '=', username)
|
|
.first()
|
|
|
|
if ( !user ) {
|
|
return http(HTTPStatus.NOT_FOUND)
|
|
}
|
|
|
|
return json(await user.toWebfinger())
|
|
}
|
|
|
|
}
|