mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 08:32:25 +01:00
added updated time to Serie and Book (maxOf(creation time, last modified time))
This commit is contained in:
parent
9243ab50d1
commit
57bfc54863
3 changed files with 20 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package org.gotson.komga.domain.model
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference
|
||||
import java.net.URL
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
import javax.persistence.GeneratedValue
|
||||
|
|
@ -16,6 +17,7 @@ data class Book(
|
|||
|
||||
val name: String,
|
||||
val url: URL,
|
||||
val updated: LocalDateTime,
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JsonManagedReference
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.gotson.komga.domain.model
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference
|
||||
import java.net.URL
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.CascadeType
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.FetchType
|
||||
|
|
@ -17,6 +18,7 @@ data class Serie(
|
|||
|
||||
val name: String,
|
||||
val url: URL,
|
||||
val updated: LocalDateTime,
|
||||
|
||||
@OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "serie")
|
||||
@JsonBackReference
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import org.gotson.komga.domain.model.Serie
|
|||
import org.springframework.stereotype.Service
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.attribute.FileTime
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import kotlin.streams.asSequence
|
||||
import kotlin.streams.toList
|
||||
|
||||
|
|
@ -31,17 +35,27 @@ class FileSystemScanner(
|
|||
.map {
|
||||
Book(
|
||||
name = FilenameUtils.getBaseName(it.fileName.toString()),
|
||||
url = it.toUri().toURL()
|
||||
url = it.toUri().toURL(),
|
||||
updated = it.getUpdatedTime()
|
||||
)
|
||||
}.toList()
|
||||
if (books.isNullOrEmpty()) return@mapNotNull null
|
||||
Serie(
|
||||
name = dir.fileName.toString(),
|
||||
url = dir.toUri().toURL(),
|
||||
updated = dir.getUpdatedTime(),
|
||||
books = books
|
||||
).also { serie ->
|
||||
serie.books.forEach { it.serie = serie }
|
||||
}
|
||||
}.toList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Path.getUpdatedTime() =
|
||||
Files.readAttributes(this, BasicFileAttributes::class.java).let {
|
||||
maxOf(it.creationTime(), it.lastModifiedTime()).toLocalDateTime()
|
||||
}
|
||||
|
||||
fun FileTime.toLocalDateTime() =
|
||||
LocalDateTime.ofInstant(this.toInstant(), ZoneId.systemDefault())
|
||||
Loading…
Reference in a new issue