Skip to content
Open
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
7 changes: 4 additions & 3 deletions backend/src/main/kotlin/dev/dres/mgmt/cache/CacheManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ class CacheManager(private val config: Config, private val store: TransientEntit
fun asyncPreviewVideo(item: DbMediaItem, start: Long, end: Long): Future<Path> {
require(start >= 0) { "Start timestamp cannot be negative." }
require(end > start) { "End timestamp must be greater than start." }
val clampedEnd = if (item.durationMs != null) minOf(end, item.durationMs!!) else end
/** The output path generated by this [PreviewImageFromVideoRequest]. */
val output = this@CacheManager.cacheLocation.resolve("${item.mediaItemId}_${start}-${end}.mp4")
val output = this@CacheManager.cacheLocation.resolve("${item.mediaItemId}_${start}-${clampedEnd}.mp4")
if (Files.exists(output)) {
this.inTransit.remove(output)
return CompletedFuture(output)
Expand All @@ -183,13 +184,13 @@ class CacheManager(private val config: Config, private val store: TransientEntit
return try {
when(item.type()) {
MediaItemType.VIDEO -> {
if (start < item.durationMs!! && end <= item.durationMs!!) {
if (start < item.durationMs!!) {
val ret = this.executor.submit(
PreviewVideoFromVideoRequest(
item.pathToOriginal(),
output,
start,
end
clampedEnd
)
)
this@CacheManager.inTransit[output] = ret
Expand Down