This commit is contained in:
Aria Moradi 2021-04-28 10:25:01 +04:30
parent 449d12779a
commit 3d2fee19bb
2 changed files with 28 additions and 21 deletions

View File

@ -28,6 +28,13 @@ import org.kodein.di.instance
import java.io.InputStream import java.io.InputStream
object Manga { 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 { suspend fun getManga(mangaId: Int, proxyThumbnail: Boolean = true): MangaDataClass {
var mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!! } var mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!! }
@ -66,7 +73,7 @@ object Manga {
it[MangaTable.artist] = fetchedManga.artist it[MangaTable.artist] = fetchedManga.artist
it[MangaTable.author] = fetchedManga.author 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.genre] = fetchedManga.genre
it[MangaTable.status] = fetchedManga.status it[MangaTable.status] = fetchedManga.status
if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url!!.isNotEmpty()) if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url!!.isNotEmpty())

View File

@ -65,9 +65,9 @@ object LegacyBackupImport : LegacyBackupBase() {
""" """
Restore Errors: Restore Errors:
${ ${
errors.map { errors.map {
"${it.first} - ${it.second}" "${it.first} - ${it.second}"
}.joinToString("\n") }.joinToString("\n")
} }
Restore Summary: Restore Summary:
- Missing Sources: - Missing Sources:
@ -94,25 +94,25 @@ object LegacyBackupImport : LegacyBackupBase() {
private suspend fun restoreManga(mangaJson: JsonObject) { private suspend fun restoreManga(mangaJson: JsonObject) {
val manga = parser.fromJson<MangaImpl>( val manga = parser.fromJson<MangaImpl>(
mangaJson.get( mangaJson.get(
Backup.MANGA Backup.MANGA
) )
) )
val chapters = parser.fromJson<List<ChapterImpl>>( val chapters = parser.fromJson<List<ChapterImpl>>(
mangaJson.get(Backup.CHAPTERS) mangaJson.get(Backup.CHAPTERS)
?: JsonArray() ?: JsonArray()
) )
val categories = parser.fromJson<List<String>>( val categories = parser.fromJson<List<String>>(
mangaJson.get(Backup.CATEGORIES) mangaJson.get(Backup.CATEGORIES)
?: JsonArray() ?: JsonArray()
) )
val history = parser.fromJson<List<DHistory>>( val history = parser.fromJson<List<DHistory>>(
mangaJson.get(Backup.HISTORY) mangaJson.get(Backup.HISTORY)
?: JsonArray() ?: JsonArray()
) )
val tracks = parser.fromJson<List<TrackImpl>>( val tracks = parser.fromJson<List<TrackImpl>>(
mangaJson.get(Backup.TRACK) mangaJson.get(Backup.TRACK)
?: JsonArray() ?: JsonArray()
) )
val source = try { val source = try {
@ -144,12 +144,12 @@ object LegacyBackupImport : LegacyBackupBase() {
* @param tracks tracking data from json * @param tracks tracking data from json
*/ */
private suspend fun restoreMangaData( private suspend fun restoreMangaData(
manga: Manga, manga: Manga,
source: Source, source: Source,
chapters: List<Chapter>, chapters: List<Chapter>,
categories: List<String>, categories: List<String>,
history: List<DHistory>, history: List<DHistory>,
tracks: List<Track> tracks: List<Track>
) { ) {
val fetchedManga = fetchManga(source, manga) val fetchedManga = fetchManga(source, manga)