Skip to content

Commit

Permalink
Added comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
b0wter committed Dec 28, 2018
1 parent af74768 commit 91e9eb8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/webapi/DownloadHandler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ open Giraffe
open WebApi

/// <summary>
/// Creates a 404 response for the given context.
/// </summary>
let create404 (ctx: HttpContext) (next: HttpFunc) responseText =
ctx.Response.StatusCode <- 404
Views.badRequestView responseText |> htmlView

let failWithStatusCodeAndMessage (ctx: HttpContext) (next: HttpFunc) (statusCode: int) (message: string) =
do ctx.SetStatusCode(500)
/// Sets the error status code and the error message in the given context.
/// </Summary>
let private failWithStatusCodeAndMessage (ctx: HttpContext) (next: HttpFunc) (statusCode: int) (message: string) =
do ctx.SetStatusCode(statusCode)
do ctx.Items.Add("errormessage", message)
next ctx

Expand All @@ -39,7 +35,7 @@ let private getFileStreamResponseAsync file downloadname (ctx: HttpContext) (nex
None
None
| None ->
return! (create404 ctx next "Download stream not set. Please contact the administrator.") next ctx
return! (failWithStatusCodeAndMessage ctx next 500 "Download stream not set. Please contact the administrator.")
}

/// <summary>
Expand All @@ -49,7 +45,7 @@ let private getFileStreamResponseAsync file downloadname (ctx: HttpContext) (nex
/// <remarks>
/// This is useful because the filename might contains a relative path oder a folder name.
/// </summary>
let createCompletePathAndFilename basePath filename =
let private createCompletePathAndFilename basePath filename =
let fullpath = IO.Path.Combine(basePath, filename)
let basePath = IO.Path.GetDirectoryName(fullpath)
let filename = IO.Path.GetFileName(fullpath);
Expand Down Expand Up @@ -78,6 +74,9 @@ let requiresQueryParameters (parameters: string seq) (addToContex: bool) : HttpH
return! next ctx
}

/// <summary>
/// Checks if the context contains a filename item and if that filename points to an existing file.
/// </summary>
let requiresExistanceOfFileInContext (basePath: string) : HttpHandler =
fun (next: HttpFunc) (ctx: HttpContext) ->
task {
Expand All @@ -94,6 +93,9 @@ let requiresExistanceOfFileInContext (basePath: string) : HttpHandler =
return None
}

/// <summary>
/// Searches for a given file, checks for valid tokens and returns a FileStream.
/// </summary>
let getDownloadFilestream (basePath: string) (downloadLifeTime: TimeSpan) (tokenLifeTime: TimeSpan) : HttpHandler =
fun (next: HttpFunc) (ctx: HttpContext) ->
task {
Expand Down

0 comments on commit 91e9eb8

Please sign in to comment.