-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #1760
- Loading branch information
Showing
26 changed files
with
507 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
komga/src/flyway/resources/db/migration/sqlite/V20250108172343__koreader_hash.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE LIBRARY | ||
add column HASH_KOREADER boolean NOT NULL DEFAULT 0; | ||
|
||
ALTER TABLE BOOK | ||
ADD COLUMN FILE_HASH_KOREADER varchar NOT NULL DEFAULT ''; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ enum class UserRoles { | |
FILE_DOWNLOAD, | ||
PAGE_STREAMING, | ||
KOBO_SYNC, | ||
KOREADER_SYNC, | ||
; | ||
|
||
companion object { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
komga/src/main/kotlin/org/gotson/komga/infrastructure/hash/KoreaderHasher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.gotson.komga.infrastructure.hash | ||
|
||
import com.appmattus.crypto.Algorithm | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Component | ||
import java.io.RandomAccessFile | ||
import java.nio.file.Path | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
@Component | ||
class KoreaderHasher { | ||
fun computeHash(path: Path): String { | ||
logger.debug { "Koreader hashing: $path" } | ||
|
||
return partialMd5(path) | ||
} | ||
|
||
/** | ||
* From https://github.com/koreader/koreader/blob/5bd3f3b42c95fd143d98f8fc9695d486fd92b7c8/frontend/util.lua#L1093-L1119 | ||
*/ | ||
@OptIn(ExperimentalStdlibApi::class) | ||
private fun partialMd5(path: Path): String { | ||
val step = 1024L | ||
val size = 1024 | ||
val digest = Algorithm.MD5.createDigest() | ||
|
||
val file = RandomAccessFile(path.toFile(), "r") | ||
|
||
val buffer = ByteArray(size) | ||
(-1..10).forEach { | ||
file.seek(step shl (2 * it)) | ||
val s = file.read(buffer) | ||
if (s > 0) digest.update(buffer) | ||
} | ||
|
||
return digest.digest().toHexString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.