Ignore non-existent galleries during favorites sync

This commit is contained in:
NerdNumber9
2019-04-14 18:53:34 -04:00
parent 98ac8a69c2
commit 77c07d13c0
5 changed files with 47 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.EHentai
import eu.kanade.tachiyomi.util.syncChaptersWithSource
import exh.metadata.metadata.EHentaiSearchMetadata
import okhttp3.MediaType
@ -186,6 +187,11 @@ class GalleryAdder {
return GalleryAddEvent.Success(url, manga)
} catch(e: Exception) {
XLog.w("Could not add gallery!", e)
if(e is EHentai.GalleryNotFoundException) {
return GalleryAddEvent.Fail.NotFound(url)
}
return GalleryAddEvent.Fail.Error(url,
((e.message ?: "Unknown error!") + " (Gallery: $url)").trim())
}
@ -223,7 +229,10 @@ sealed class GalleryAddEvent {
override val logMessage = "Unknown gallery type for gallery: $galleryUrl"
}
class Error(override val galleryUrl: String,
open class Error(override val galleryUrl: String,
override val logMessage: String): Fail()
class NotFound(galleryUrl: String):
Error(galleryUrl, "Gallery does not exist: $galleryUrl")
}
}

View File

@ -323,6 +323,12 @@ class FavoritesSyncHelper(val context: Context) {
EXH_SOURCE_ID)
if(result is GalleryAddEvent.Fail) {
if(result is GalleryAddEvent.Fail.NotFound) {
XLog.e("Remote gallery does not exist, skipping: %s!", it.getUrl())
// Skip this gallery, it no longer exists
return@forEachIndexed
}
val errorString = "Failed to add gallery to local database: " + when (result) {
is GalleryAddEvent.Fail.Error -> "'${it.title}' ${result.logMessage}"
is GalleryAddEvent.Fail.UnknownType -> "'${it.title}' (${result.galleryUrl}) is not a valid gallery!"

View File

@ -43,7 +43,6 @@ class BatchAddPresenter: BasePresenter<BatchAddController>() {
eventRelay?.call((when (result) {
is GalleryAddEvent.Success -> "[OK]"
is GalleryAddEvent.Fail -> "[ERROR]"
else -> "[???]"
}) + " " + result.logMessage)
}