Skip to content

Commit

Permalink
Revert "Fixing the TIFF issue. Related to : guardian#3049"
Browse files Browse the repository at this point in the history
This reverts commit ad8e76b.
  • Loading branch information
gribeiro committed Dec 8, 2020
1 parent f376691 commit b0cf626
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions image-loader/app/model/ImageUpload.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case object OptimisedPng {
case Some("True Color with Alpha") => true
case _ => false
}
case Some(Tiff) => true
case Some(Tiff) => false
case _ => false
}
}
Expand Down Expand Up @@ -88,10 +88,10 @@ object OptimisedPngOps {
uploadRequest: UploadRequest,
fileMetadata: FileMetadata,
config: ImageUploadOpsCfg,
storeOrProject: (UploadRequest, File) => Future[S3Object], sourceMimeType: Option[MimeType])
storeOrProject: (UploadRequest, File) => Future[S3Object])
(implicit ec: ExecutionContext, logMarker: LogMarker): OptimisedPng = {

val result = if (!OptimisedPng.shouldOptimise(sourceMimeType, fileMetadata)) {
val result = if (!OptimisedPng.shouldOptimise(uploadRequest.mimeType, fileMetadata)) {
OptimisedPng(Future(None), isPng24 = false, None)
} else {
val optimisedFile: File = toOptimisedFile(file, uploadRequest, config)
Expand Down Expand Up @@ -337,7 +337,7 @@ object Uploader {
val uploadedFile = uploadRequest.tempFile

val fileMetadataFuture = toFileMetadata(uploadedFile, uploadRequest.imageId, uploadRequest.mimeType)

Logger.info("Have read file headers")

fileMetadataFuture.flatMap(fileMetadata => {
Expand Down Expand Up @@ -374,25 +374,25 @@ object Uploader {
val sourceDimensionsFuture = FileMetadataReader.dimensions(uploadedFile, uploadRequest.mimeType)

// if the file needs pre-processing into a supported type of file, do it now and create the new upload request.
createOptimisedFileFuture(uploadRequest, deps).flatMap(optmizedUploadRequest => {
createOptimisedFileFuture(uploadRequest, deps).flatMap(uploadRequest => {
val sourceStoreFuture = storeOrProjectOriginalFile(uploadRequest)
val toOptimiseFile = optmizedUploadRequest.tempFile
val thumbFuture = createThumbFuture(fileMetadataFuture, colourModelFuture, optmizedUploadRequest, deps)
val toOptimiseFile = uploadRequest.tempFile
val thumbFuture = createThumbFuture(fileMetadataFuture, colourModelFuture, uploadRequest, deps)
Logger.info("thumbnail created")

//problematic code is here: toOptimiseFile
val optimisedPng = OptimisedPngOps.build(
toOptimiseFile,
optmizedUploadRequest,
uploadRequest,
fileMetadata,
config,
storeOrProjectOptimisedPNG, uploadRequest.mimeType)(ec, logMarker)
storeOrProjectOptimisedPNG)(ec, logMarker)
Logger.info(s"optimised image ($toOptimiseFile) created")

bracket(thumbFuture)(_.delete) { thumb =>
// Run the operations in parallel
val thumbStoreFuture = storeOrProjectThumbFile(optmizedUploadRequest, thumb)
val thumbDimensionsFuture = FileMetadataReader.dimensions(thumb, optmizedUploadRequest.mimeType)
val thumbStoreFuture = storeOrProjectThumbFile(uploadRequest, thumb)
val thumbDimensionsFuture = FileMetadataReader.dimensions(thumb, uploadRequest.mimeType)

val finalImage = toFinalImage(
stores.metadataStore,
Expand All @@ -409,7 +409,6 @@ object Uploader {
Logger.info(s"Deleting temp file ${uploadedFile.getAbsolutePath}")
uploadedFile.delete()
toOptimiseFile.delete()
optmizedUploadRequest.tempFile.delete()
finalImage
}
})
Expand Down Expand Up @@ -533,12 +532,12 @@ class Uploader(val store: ImageLoaderStore,

def fromUploadRequest(uploadRequest: UploadRequest)
(implicit logMarker: LogMarker): Future[ImageUpload] = {

val sideEffectDependencies = ImageUploadOpsDependencies(toImageUploadOpsCfg(config), imageOps,
storeSource, storeThumbnail, storeOptimisedPng)

val finalImage = fromUploadRequestShared(uploadRequest, sideEffectDependencies)

finalImage.map(img => Stopwatch("finalImage"){ImageUpload(uploadRequest, img)})
}

Expand Down

0 comments on commit b0cf626

Please sign in to comment.