Skip to content

Commit

Permalink
fix: get dimension failed
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Feb 17, 2025
1 parent f46f636 commit 8ae2e84
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.storyteller_f.media

import com.ashampoo.kim.common.convertToPhotoMetadata
import com.ashampoo.kim.jvm.KimJvm
import com.storyteller_f.shared.model.Dimension
import com.storyteller_f.shared.model.MediaInfo
import com.storyteller_f.shared.model.MediaItem
import io.github.aakira.napier.Napier
Expand Down Expand Up @@ -63,7 +60,7 @@ class FileSystemMediaService(private val url: String, base: String) : MediaServi
val file = File(root, "$bucketName/$it")
if (file.exists()) {
val item = stat(it, file)
val dimension = getDimension(file)
val dimension = getDimension(file, item.contentType)
MediaInfo("${url}amedia/$it", item, dimension)
} else {
null
Expand All @@ -73,18 +70,6 @@ class FileSystemMediaService(private val url: String, base: String) : MediaServi
})
}

private fun getDimension(
file: File
) = KimJvm.readMetadata(file)?.convertToPhotoMetadata()?.let {
val width = it.widthPx
val height = it.heightPx
if (width != null && height != null) {
Dimension(width, height)
} else {
null
}
}

private fun stat(it: String, file: File): MediaItem {
val contentType = kotlin.runCatching {
tika.detect(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fun loadAvif() {
}
}

private fun getDimension(
fun getDimension(
file: File,
contentType: String
): Dimension? {
Expand Down

0 comments on commit 8ae2e84

Please sign in to comment.