add Local Source

This commit is contained in:
Aria Moradi
2021-09-18 00:47:50 +04:30
parent 52a064ae45
commit 1ca11fdd34
14 changed files with 455 additions and 234 deletions

View File

@@ -75,7 +75,7 @@ object Manga {
transaction {
MangaTable.update({ MangaTable.id eq mangaId }) {
it[MangaTable.title] = fetchedManga.title
it[MangaTable.initialized] = true
it[MangaTable.artist] = fetchedManga.artist
@@ -86,7 +86,11 @@ object Manga {
if (fetchedManga.thumbnail_url != null && fetchedManga.thumbnail_url.orEmpty().isNotEmpty())
it[MangaTable.thumbnail_url] = fetchedManga.thumbnail_url
it[MangaTable.realUrl] = try { source.mangaDetailsRequest(sManga).url.toString() } catch (e: Exception) { null }
it[MangaTable.realUrl] = try {
source.mangaDetailsRequest(sManga).url.toString()
} catch (e: Exception) {
null
}
}
}
@@ -151,14 +155,20 @@ object Manga {
val fileName = mangaId.toString()
return getCachedImageResponse(saveDir, fileName) {
getManga(mangaId) // make sure is initialized
val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }
val sourceId = mangaEntry[MangaTable.sourceReference]
val source = getHttpSource(sourceId)
val thumbnailUrl = mangaEntry[MangaTable.thumbnail_url]!!
val thumbnailUrl: String = mangaEntry[MangaTable.thumbnail_url]
?: if (!mangaEntry[MangaTable.initialized]) {
// initialize then try again
getManga(mangaId)
transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }[MangaTable.thumbnail_url]!!
} else {
// source provides no thumbnail url for this manga
throw NullPointerException()
}
source.client.newCall(
GET(thumbnailUrl, source.headers)