LANraragi: Update to API 0.7.2 (#4571)

LANraragi: Update to API 0.7.2
This commit is contained in:
RePod 2020-10-10 21:44:53 -04:00 committed by GitHub
parent 4bfa1482ef
commit 36f5609434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'LANraragi' extName = 'LANraragi'
pkgNameSuffix = 'all.lanraragi' pkgNameSuffix = 'all.lanraragi'
extClass = '.LANraragi' extClass = '.LANraragi'
extVersionCode = 1 extVersionCode = 2
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -5,11 +5,13 @@ import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.support.v7.preference.EditTextPreference import android.support.v7.preference.EditTextPreference
import android.support.v7.preference.PreferenceScreen import android.support.v7.preference.PreferenceScreen
import android.util.Base64
import com.github.salomonbrys.kotson.fromJson import com.github.salomonbrys.kotson.fromJson
import com.google.gson.Gson import com.google.gson.Gson
import eu.kanade.tachiyomi.extension.all.lanraragi.model.ArchivePage import eu.kanade.tachiyomi.extension.all.lanraragi.model.ArchivePage
import eu.kanade.tachiyomi.extension.all.lanraragi.model.ArchiveSearchResult import eu.kanade.tachiyomi.extension.all.lanraragi.model.ArchiveSearchResult
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
@ -17,6 +19,7 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import okhttp3.Headers
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -49,20 +52,23 @@ open class LANraragi : ConfigurableSource, HttpSource() {
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val id = getId(response) val id = getId(response)
val uri = getApiUriBuilder("/api/extract") val uri = getApiUriBuilder("/api/archives/$id/extract")
uri.appendQueryParameter("id", id)
return listOf( return listOf(
SChapter.create().apply { SChapter.create().apply {
val uriBuild = uri.build() val uriBuild = uri.build()
url = "${uriBuild.encodedPath}?${uriBuild.encodedQuery}" url = uriBuild.toString()
chapter_number = 1F chapter_number = 1F
name = "Chapter" name = "Chapter"
} }
) )
} }
override fun pageListRequest(chapter: SChapter): Request {
return POST(chapter.url, headers)
}
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val archivePage = gson.fromJson<ArchivePage>(response.body()!!.string()) val archivePage = gson.fromJson<ArchivePage>(response.body()!!.string())
@ -100,7 +106,7 @@ open class LANraragi : ConfigurableSource, HttpSource() {
uri.appendQueryParameter("filter", query) uri.appendQueryParameter("filter", query)
} }
return GET(uri.toString()) return GET(uri.toString(), headers)
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
@ -124,6 +130,13 @@ open class LANraragi : ConfigurableSource, HttpSource() {
) )
} }
override fun headersBuilder() = Headers.Builder().apply {
if (apiKey.isNotEmpty()) {
val apiKey64 = Base64.encodeToString(apiKey.toByteArray(), Base64.DEFAULT).trim()
add("Authorization", "Bearer $apiKey64")
}
}
// Preferences // Preferences
private val preferences: SharedPreferences by lazy { private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000) Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
@ -224,16 +237,12 @@ open class LANraragi : ConfigurableSource, HttpSource() {
// Helper // Helper
private fun getApiUriBuilder(path: String): Uri.Builder { private fun getApiUriBuilder(path: String): Uri.Builder {
val uri = Uri.parse("$baseUrl$path").buildUpon() val uri = Uri.parse("$baseUrl$path").buildUpon()
if (apiKey.isNotEmpty()) {
uri.appendQueryParameter("key", apiKey)
}
return uri return uri
} }
private fun getThumbnailUri(id: String): String { private fun getThumbnailUri(id: String): String {
val uri = getApiUriBuilder("/api/thumbnail") val uri = getApiUriBuilder("/api/archives/$id/thumbnail")
uri.appendQueryParameter("id", id)
return uri.toString() return uri.toString()
} }