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.

30 lines
947 B

import {Controller, http, HTTPStatus, Inject, Injectable, Logging, view} from '@extollo/lib'
import {Snippet} from '../../models/Snippet.model'
/**
* Snippets Controller
* ------------------------------------
* Backend for routes that deal with code snippets.
*/
@Injectable()
export class Snippets extends Controller {
@Inject()
protected readonly logging!: Logging
public async viewSnippet(snippet: Snippet) {
const needsAccessKey = snippet?.accessKey && snippet.accessKey !== this.request.input('accessKey')
const needsConfirm = snippet?.singleAccessOnly && !this.request.input('confirmSingleAccess')
if ( snippet?.singleAccessOnly && !needsAccessKey && !needsConfirm ) {
await snippet.delete()
}
return view('snippet', {
snippet,
needsAccessKey,
needsConfirm,
accessKey: this.request.input('accessKey'),
})
}
}