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() .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() .where('username', '=', username) .first() if ( !user ) { return http(HTTPStatus.NOT_FOUND) } return json(await user.toWebfinger()) } }