mirror of
https://github.com/gotson/komga.git
synced 2025-12-26 10:24:04 +01:00
change: retrieve file size of books when scanning. Add file size in REST API and OPDS.
This commit is contained in:
parent
bc0037d201
commit
d5eb4ca2c8
7 changed files with 33 additions and 9 deletions
|
|
@ -76,6 +76,8 @@ dependencies {
|
|||
implementation("com.twelvemonkeys.imageio:imageio-tiff:3.4.2")
|
||||
implementation(files("$projectDir/libs/webp-imageio-decoder-plugin-0.2.jar"))
|
||||
|
||||
implementation("com.jakewharton.byteunits:byteunits:0.9.1")
|
||||
|
||||
runtimeOnly("com.h2database:h2")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.gotson.komga.domain.model
|
||||
|
||||
import com.jakewharton.byteunits.BinaryByteUnit
|
||||
import org.apache.commons.io.FilenameUtils
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
|
|
@ -29,7 +30,10 @@ class Book(
|
|||
var url: URL,
|
||||
|
||||
@Column(name = "file_last_modified", nullable = false)
|
||||
var fileLastModified: LocalDateTime
|
||||
var fileLastModified: LocalDateTime,
|
||||
|
||||
@Column(name = "file_size", nullable = false)
|
||||
var fileSize: Long = 0
|
||||
) : AuditableEntity() {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
@ -49,9 +53,13 @@ class Book(
|
|||
field = value
|
||||
}
|
||||
|
||||
fun filename(): String = FilenameUtils.getName(url.toString())
|
||||
fun fileName(): String = FilenameUtils.getName(url.toString())
|
||||
|
||||
fun fileExtension(): String = FilenameUtils.getExtension(url.toString())
|
||||
|
||||
fun path(): Path = Paths.get(this.url.toURI())
|
||||
|
||||
fun fileSizeHumanReadable(): String = BinaryByteUnit.format(fileSize)
|
||||
|
||||
override fun toString(): String = url.toURI().path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class FileSystemScanner(
|
|||
Book(
|
||||
name = FilenameUtils.getBaseName(it.fileName.toString()),
|
||||
url = it.toUri().toURL(),
|
||||
fileLastModified = it.getUpdatedTime()
|
||||
fileLastModified = it.getUpdatedTime(),
|
||||
fileSize = Files.readAttributes(it, BasicFileAttributes::class.java).size()
|
||||
)
|
||||
}.toList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ class LibraryScanner(
|
|||
logger.info { "Book changed on disk, update and reset metadata status: $newBook" }
|
||||
existingBook.fileLastModified = newBook.fileLastModified
|
||||
existingBook.name = newBook.name
|
||||
existingBook.fileSize = newBook.fileSize
|
||||
existingBook.metadata.reset()
|
||||
}
|
||||
existingBook
|
||||
|
|
|
|||
|
|
@ -75,21 +75,21 @@ class OpdsController(
|
|||
title = "All series",
|
||||
updated = ZonedDateTime.now(),
|
||||
id = ID_SERIES_ALL,
|
||||
content = "All series.",
|
||||
content = "Browse by series",
|
||||
link = OpdsLinkFeedNavigation(OpdsLinkRel.SUBSECTION, "${ROUTE_BASE}${ROUTE_SERIES_ALL}")
|
||||
),
|
||||
OpdsEntryNavigation(
|
||||
title = "Latest series",
|
||||
updated = ZonedDateTime.now(),
|
||||
id = ID_SERIES_LATEST,
|
||||
content = "Latest series.",
|
||||
content = "Browse latest series",
|
||||
link = OpdsLinkFeedNavigation(OpdsLinkRel.SUBSECTION, "${ROUTE_BASE}${ROUTE_SERIES_LATEST}")
|
||||
),
|
||||
OpdsEntryNavigation(
|
||||
title = "All libraries",
|
||||
updated = ZonedDateTime.now(),
|
||||
id = ID_LIBRARIES_ALL,
|
||||
content = "All libraries.",
|
||||
content = "Browse by library",
|
||||
link = OpdsLinkFeedNavigation(OpdsLinkRel.SUBSECTION, "${ROUTE_BASE}${ROUTE_LIBRARIES_ALL}")
|
||||
)
|
||||
)
|
||||
|
|
@ -248,11 +248,11 @@ class OpdsController(
|
|||
title = name,
|
||||
updated = lastModifiedDate?.atZone(ZoneId.systemDefault()) ?: ZonedDateTime.now(),
|
||||
id = id.toString(),
|
||||
content = "",
|
||||
content = "$name (${fileExtension().toUpperCase()}) (${fileSizeHumanReadable()})",
|
||||
links = listOf(
|
||||
OpdsLinkImageThumbnail("image/jpeg", "/api/v1/series/${series.id}/books/$id/thumbnail"),
|
||||
OpdsLinkImage(metadata.pages[0].mediaType, "/api/v1/series/${series.id}/books/$id/pages/1"),
|
||||
OpdsLinkFileAcquisition(metadata.mediaType, "/api/v1/series/${series.id}/books/$id/file/${filename()}"),
|
||||
OpdsLinkFileAcquisition(metadata.mediaType, "/api/v1/series/${series.id}/books/$id/file/${fileName()}"),
|
||||
OpdsLinkPageStreaming("image/jpeg", "/api/v1/series/${series.id}/books/$id/pages/{pageNumber}?convert=jpeg&zero_based=true", metadata.pages.size)
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ class SeriesController(
|
|||
ResponseEntity.ok()
|
||||
.headers(HttpHeaders().apply {
|
||||
contentDisposition = ContentDisposition.builder("attachment")
|
||||
.filename(book.filename())
|
||||
.filename(book.fileName())
|
||||
.build()
|
||||
})
|
||||
.contentType(getMediaTypeOrDefault(book.metadata.mediaType))
|
||||
|
|
@ -299,6 +299,8 @@ data class BookDto(
|
|||
val url: String,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val lastModified: LocalDateTime?,
|
||||
val sizeBytes: Long,
|
||||
val size: String,
|
||||
val metadata: BookMetadataDto
|
||||
)
|
||||
|
||||
|
|
@ -313,6 +315,8 @@ fun Book.toDto() =
|
|||
name = name,
|
||||
url = url.toURI().path,
|
||||
lastModified = lastModifiedDate?.toUTC(),
|
||||
sizeBytes = fileSize,
|
||||
size = fileSizeHumanReadable(),
|
||||
metadata = BookMetadataDto(
|
||||
status = metadata.status.toString(),
|
||||
mediaType = metadata.mediaType ?: ""
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
alter table book
|
||||
add (file_size bigint default 0);
|
||||
|
||||
-- force rescan to update file size of all books
|
||||
update series
|
||||
set file_last_modified = '1970-01-01 00:00:00';
|
||||
update book
|
||||
set file_last_modified = '1970-01-01 00:00:00';
|
||||
Loading…
Reference in a new issue