diff --git a/komga/build.gradle.kts b/komga/build.gradle.kts index 5fc8c28a1..82537875f 100644 --- a/komga/build.gradle.kts +++ b/komga/build.gradle.kts @@ -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") { diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/model/Book.kt b/komga/src/main/kotlin/org/gotson/komga/domain/model/Book.kt index bae427df5..3c976e374 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/model/Book.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/model/Book.kt @@ -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 } diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/FileSystemScanner.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/FileSystemScanner.kt index 9375863da..4e8fc2c3d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/FileSystemScanner.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/FileSystemScanner.kt @@ -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() } diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryScanner.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryScanner.kt index ea59913a9..144753be8 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryScanner.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryScanner.kt @@ -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 diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/opds/OpdsController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/opds/OpdsController.kt index f55ffc916..85dd98cb8 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/opds/OpdsController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/opds/OpdsController.kt @@ -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) ) ) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt index 8d3079310..4208591d6 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/SeriesController.kt @@ -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 ?: "" diff --git a/komga/src/main/resources/db/migration/V20191029153618__book_filesize.sql b/komga/src/main/resources/db/migration/V20191029153618__book_filesize.sql new file mode 100644 index 000000000..c4d558ae1 --- /dev/null +++ b/komga/src/main/resources/db/migration/V20191029153618__book_filesize.sql @@ -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';