def generateProxy()

in app/controllers/ProxiesController.scala [269:335]


  def generateProxy(fileId:String, typeStr:String) = IsAuthenticatedAsync { _=> _=>
    try {
      val pt = ProxyType.withName(typeStr.toUpperCase)
      indexer.getById(fileId).flatMap(entry=>{
        val canContinue = entry.mimeType.major.toLowerCase match {
          case "application"=>
            if(entry.mimeType.minor.toLowerCase=="octet-stream"){
              //application/octet-stream could be anything, so let it go through.
              Right(true)
            } else {
              Left(s"Can't proxy media of type ${entry.mimeType.toString}")
            }
          case "binary"=>
            if(entry.mimeType.minor.toLowerCase=="octet-stream"){
              //application/octet-stream could be anything, so let it go through.
              Right(true)
            } else {
              Left(s"Can't proxy media of type ${entry.mimeType.toString}")
            }
          case "video"=>  //video can proxy to anything
            Right(true)
          case "audio"=>
            if(pt==ProxyType.VIDEO){
              Left("Can't make a video proxy of an audio item")
            } else {
              Right(true)
            }
          case "image"=>
            if(pt==ProxyType.AUDIO || pt==ProxyType.VIDEO){
              Left("Can't make audio or video proxy of an image item")
            } else {
              Right(true)
            }
          case _=>
            Left(s"Can't proxy media of type ${entry.mimeType.toString}")
        }

        canContinue match {
          case Right(_)=>
            val requestType = pt match {
              case ProxyType.THUMBNAIL=>RequestType.THUMBNAIL
              case _=>RequestType.PROXY
            }
            proxyGenerators.requestProxyJob(requestType,entry,Some(pt)).map({
              case Success(jobId)=>
                Ok(TranscodeStartedResponse("transcode_started", jobId, None).asJson)
              case Failure(err)=>
                InternalServerError(GenericErrorResponse("not_started", err.toString).asJson)
            })
          case Left(err)=>
            Future(BadRequest(GenericErrorResponse("bad_request",err).asJson))
        }

      }).recoverWith({
        case timeout:AskTimeoutException=>
          logger.warn("Ask timed out: ", timeout)
          Future(Ok(GenericErrorResponse("warning", "proxy request timed out server-side, may not have started").asJson))
        case ex:Throwable=>
          logger.error("Could not trigger proxy: ", ex)
          Future(InternalServerError(GenericErrorResponse("error", ex.toString).asJson))
      })
    } catch {
      case ex:Throwable=>
        logger.error("Could not request proxy: ", ex)
        Future(BadRequest(GenericErrorResponse("bad_request", ex.toString).asJson))
    }
  }