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.
23 lines
609 B
23 lines
609 B
3 years ago
|
import {Controller, view, Inject, Injectable, HTTPStatus, http, redirect} from '@extollo/lib'
|
||
|
import {GoLink} from '../../models/GoLink.model'
|
||
|
|
||
|
/**
|
||
|
* GoLinks Controller
|
||
|
*/
|
||
|
@Injectable()
|
||
|
export class GoLinks extends Controller {
|
||
|
async launch() {
|
||
|
const short = this.request.safe('short').string()
|
||
|
const link = await GoLink.query<GoLink>()
|
||
|
.where('active', '=', true)
|
||
|
.where('short', '=', short)
|
||
|
.first()
|
||
|
|
||
|
if ( !link ) {
|
||
|
return http(HTTPStatus.http404, 'Invalid or expired link.')
|
||
|
}
|
||
|
|
||
|
return redirect(link.url)
|
||
|
}
|
||
|
}
|