in app/controllers/Application.scala [61:100]
def getMaybeMimetype(entry:ObjectMatrixEntry):Option[String] = entry.attributes.flatMap(_.stringValues.get("MXFS_MIMETYPE"))
def headTargetContent(targetUriString:String) = IsAuthenticatedAsync { uid=> request=>
val maybeTargetUri = Try {
URI.create(targetUriString)
}
val maybeLocator = maybeTargetUri.flatMap(targetUri => OMLocator.fromUri(targetUri))
/*
look up the object, using cache if possible, and get hold of the metadata
*/
val objectEntryFut = Future.fromTry(maybeLocator).flatMap(locator=>{
(objectCache ? Lookup(locator)).mapTo[OCMsg].map({
case ObjectNotFound(_) =>
val auditFile = AuditFile("",locator.filePath)
auditActor ! actors.Audit.LogEvent(AuditEvent.NOTFOUND, uid, Some(auditFile), Seq())
Left(NotFound(s"could not find object $targetUriString")) //FIXME: replace with proper json response
case ObjectLookupFailed(_, err) =>
val auditFile = AuditFile("",locator.filePath)
auditActor ! actors.Audit.LogEvent(AuditEvent.OMERROR, uid, Some(auditFile), Seq(),notes=Some(err.toString))
logger.error(s"Could not look up object for $targetUriString: ", err)
Left(InternalServerError(s"lookup failed for $targetUriString"))
case ObjectFound(_, objectEntry) =>
val auditFile = AuditFile(objectEntry.oid,locator.filePath)
auditActor ! actors.Audit.LogEvent(AuditEvent.HEADFILE, uid, Some(auditFile), Seq())
Right(objectEntry)
})
})
objectEntryFut.map({
case Left(response)=>response
case Right(entry)=>
Result(
ResponseHeader(200,headersForEntry(entry, Seq(), getMaybeResponseSize(entry, None))),
HttpEntity.Streamed(Source.empty, getMaybeResponseSize(entry, None), getMaybeMimetype(entry))
)
})
}