Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion image-loader/app/ImageLoaderComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ImageLoaderComponents(context: Context) extends GridComponents(context, ne
}

val uploader = new Uploader(store, config, imageOperations, notifications, maybeEmbedder, imageProcessor, gridClient, auth)
val projector = Projector(config, imageOperations, imageProcessor, auth, maybeEmbedder)
val projector = Projector(config, imageOperations, imageProcessor, maybeEmbedder)
val quarantineUploader: Option[QuarantineUploader] = config.maybeQuarantineBucket.map(_ =>
new QuarantineUploader(new QuarantineStore(config), config)
)
Expand Down
12 changes: 5 additions & 7 deletions image-loader/app/controllers/ImageLoaderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,14 @@ class ImageLoaderController(auth: Authentication,

result.onComplete( _ => Try { deleteTempFile(tempFile) } )

result.map {
case Some(img) =>
logger.info(context, "image found")
Ok(Json.toJson(img)).as(ArgoMediaType)
case None =>
result.map { img =>
logger.info(context, "image found")
Ok(Json.toJson(img)).as(ArgoMediaType)
} recover {
case _: NoSuchImageExistsInS3 =>
val s3Path = "s3://" + config.imageBucket + "/" + ImageIngestOperations.fileKeyFromId(imageId)
logger.info(context, "image not found")
respondError(NotFound, "image-not-found", s"Could not find image: $imageId in s3 at $s3Path")
} recover {
case _: NoSuchImageExistsInS3 => NotFound(Json.obj("imageId" -> imageId))
case e =>
logger.error(context, s"projectImageBy request for id $imageId ended with a failure", e)
InternalServerError(Json.obj("imageId" -> imageId, "exception" -> e.getMessage))
Expand Down
14 changes: 5 additions & 9 deletions image-loader/app/model/Projector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object Projector {

import Uploader.toImageUploadOpsCfg

def apply(config: ImageLoaderConfig, imageOps: ImageOperations, processor: ImageProcessor, auth: Authentication, maybeEmbedder: Option[Embedder])(implicit ec: ExecutionContext): Projector
= new Projector(toImageUploadOpsCfg(config), S3Ops.buildS3Client(config), imageOps, processor, auth, maybeEmbedder)
def apply(config: ImageLoaderConfig, imageOps: ImageOperations, processor: ImageProcessor, maybeEmbedder: Option[Embedder])(implicit ec: ExecutionContext): Projector
= new Projector(toImageUploadOpsCfg(config), S3Ops.buildS3Client(config), imageOps, processor, maybeEmbedder)
}

case class S3FileExtractedMetadata(
Expand Down Expand Up @@ -84,13 +84,12 @@ class Projector(config: ImageUploadOpsCfg,
s3: AmazonS3,
imageOps: ImageOperations,
processor: ImageProcessor,
auth: Authentication,
maybeEmbedder: Option[Embedder]) extends GridLogging {

private val imageUploadProjectionOps = new ImageUploadProjectionOps(config, imageOps, processor, s3, maybeEmbedder)

def projectS3ImageById(imageId: String, tempFile: File, gridClient: GridClient, onBehalfOfFn: WSRequest => WSRequest)
(implicit ec: ExecutionContext, logMarker: LogMarker): Future[Option[Image]] = {
(implicit ec: ExecutionContext, logMarker: LogMarker): Future[Image] = {
Future {
import ImageIngestOperations.fileKeyFromId
val s3Key = fileKeyFromId(imageId)
Expand All @@ -106,14 +105,11 @@ class Projector(config: ImageUploadOpsCfg,
val digestedFile = getSrcFileDigestForProjection(s3Source, imageId, tempFile)
val extractedS3Meta = S3FileExtractedMetadata(s3Source.getObjectMetadata)

val finalImageFuture = projectImage(digestedFile, extractedS3Meta, gridClient, onBehalfOfFn)
val finalImage = Await.result(finalImageFuture, Duration.Inf)

Some(finalImage)
projectImage(digestedFile, extractedS3Meta, gridClient, onBehalfOfFn)
} finally {
s3Source.close()
}
}
}.flatten
}

private def getSrcFileDigestForProjection(s3Src: AwsS3Object, imageId: String, tempFile: File) = {
Expand Down
3 changes: 1 addition & 2 deletions image-loader/test/scala/model/ProjectorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class ProjectorTest extends AnyFreeSpec with Matchers with ScalaFutures with Moc
private val maybeEmbedder = None

private val s3 = mock[AmazonS3]
private val auth = mock[Authentication]
private val projector = new Projector(config, s3, imageOperations, ImageProcessor.identity, auth, maybeEmbedder)
private val projector = new Projector(config, s3, imageOperations, ImageProcessor.identity, maybeEmbedder)

// FIXME temporary ignored as test is not executable in CI/CD machine
// because graphic lib files like srgb.icc, cmyk.icc are in root directory instead of resources
Expand Down
Loading