def validateTokenAsync()

in app/controllers/BulkDownloadController.scala [176:201]


  def validateTokenAsync(request:Request[AnyContent], actualTokenValue:Option[String])(block: (ServerTokenEntry,String,String)=>Future[Result]):Future[Result] = {
    eitherOr(actualTokenValue, request.headers.get("X-Download-Token")) match {
      case None=>
        logger.error(s"Attempt to download with no X-Download-Token header")
        Future(BadRequest(GenericErrorResponse("bad_request","No download token in headers").asJson))
      case Some(tokenId)=>
        logger.debug(s"Got token ID $tokenId")
        serverTokenDAO.get(tokenId).flatMap({
          case Some(serverToken)=>
            logger.debug(s"Got server token $serverToken for $tokenId")
            val updatedServerToken = serverToken.copy(uses=serverToken.uses+1)
            val expirySeconds = serverToken.expiry.get.toInstant.getEpochSecond - Instant.now().getEpochSecond
          if(expirySeconds<1){
              logger.error(s"Server token $serverToken is expired")
              Future(BadRequest(GenericErrorResponse("token_error","Expired token").asJson))
            } else {
              serverTokenDAO.put(updatedServerToken, expirySeconds.toInt).flatMap(_ => {
                val idSplit = serverToken.associatedId.get.split("\\|")
                block(serverToken, idSplit.head, idSplit(1))
              })
            }
          case None=>
            Future(NotFound(GenericErrorResponse("not_found","item was not found").asJson))
        })
    }
  }