import { Status } from "../deps.ts" ; export function invalidMethod ( ) { return error ( "Invalid method" , Status . BadRequest ) ; } export function invalidAlias ( ) { return error ( "Invalid alias" , Status . BadRequest ) ; } export function aliasNotFound ( ) { return error ( "Alias not found" , Status . BadRequest ) ; } export function couldNotAuthenticate ( ) { return error ( "Could not authenticate" , Status . Unauthorized ) ; } export function error ( error , status ) { return json ( { error } , { status } ) ; } export function status ( status ) { return new Response ( undefined , { status } ) ; } export function ok ( ) { return status ( Status . OK ) ; } export function created ( ) { return status ( Status . Created ) ; } export function fileCollision ( id ) { return error ( `File already exists (${ id })` , Status . BadRequest ) ; } export function hashCollision ( id ) { return error ( `Hash collided, try changing your file slightly (${ id })` , Status . InternalServerError ) ; } export function notFound ( ) { return new Response ( "Not found" , { status : Status . NotFound } ) ; } export function html ( html , init ? ) { return new Response ( html , { status : init ?. status ?? Status . OK , headers : { "Content-Type" : "text/html; charset=utf-8" , ... init ?. headers } } ) ; } export function json ( obj , init ? ) { return new Response ( JSON . stringify ( obj ) , { status : init ?. status ?? Status . OK , headers : { "Content-Type" : "application/json; charset=utf-8" , ... init ?. headers } } ) ; } export function redirect ( location ) { return new Response ( undefined , { status : Status . TemporaryRedirect , headers : new Headers ( { "Location" : location } ) } ) ; }