From 3d2fee19bbdd52a4e20025363b3d1bb973345638 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Wed, 28 Apr 2021 10:25:01 +0430 Subject: [PATCH] refactor --- .../kotlin/ir/armor/tachidesk/impl/Manga.kt | 9 ++++- .../impl/backup/legacy/LegacyBackupImport.kt | 40 +++++++++---------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt index 5dd962e..ee08087 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Manga.kt @@ -28,6 +28,13 @@ import org.kodein.di.instance import java.io.InputStream object Manga { + private fun truncate(text: String?, maxLength: Int): String? { + return if (text?.length ?: 0 > maxLength) + text?.take(maxLength - 3) + "..." + else + text + } + suspend fun getManga(mangaId: Int, proxyThumbnail: Boolean = true): MangaDataClass { var mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!! } @@ -66,7 +73,7 @@ object Manga { it[MangaTable.artist] = fetchedManga.artist it[MangaTable.author] = fetchedManga.author - it[MangaTable.description] = if (fetchedManga.description?.length ?: 0 > 4096) fetchedManga.description?.substring(0, 4096) else fetchedManga.description + it[MangaTable.description] = truncate(fetchedManga.description, 4096) it[MangaTable.genre] = fetchedManga.genre it[MangaTable.status] = fetchedManga.status if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url!!.isNotEmpty()) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt index 4cb45f8..b17a2c3 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt @@ -65,9 +65,9 @@ object LegacyBackupImport : LegacyBackupBase() { """ Restore Errors: ${ - errors.map { - "${it.first} - ${it.second}" - }.joinToString("\n") + errors.map { + "${it.first} - ${it.second}" + }.joinToString("\n") } Restore Summary: - Missing Sources: @@ -94,25 +94,25 @@ object LegacyBackupImport : LegacyBackupBase() { private suspend fun restoreManga(mangaJson: JsonObject) { val manga = parser.fromJson( - mangaJson.get( - Backup.MANGA - ) + mangaJson.get( + Backup.MANGA + ) ) val chapters = parser.fromJson>( - mangaJson.get(Backup.CHAPTERS) - ?: JsonArray() + mangaJson.get(Backup.CHAPTERS) + ?: JsonArray() ) val categories = parser.fromJson>( - mangaJson.get(Backup.CATEGORIES) - ?: JsonArray() + mangaJson.get(Backup.CATEGORIES) + ?: JsonArray() ) val history = parser.fromJson>( - mangaJson.get(Backup.HISTORY) - ?: JsonArray() + mangaJson.get(Backup.HISTORY) + ?: JsonArray() ) val tracks = parser.fromJson>( - mangaJson.get(Backup.TRACK) - ?: JsonArray() + mangaJson.get(Backup.TRACK) + ?: JsonArray() ) val source = try { @@ -144,12 +144,12 @@ object LegacyBackupImport : LegacyBackupBase() { * @param tracks tracking data from json */ private suspend fun restoreMangaData( - manga: Manga, - source: Source, - chapters: List, - categories: List, - history: List, - tracks: List + manga: Manga, + source: Source, + chapters: List, + categories: List, + history: List, + tracks: List ) { val fetchedManga = fetchManga(source, manga)