Added Offline mode
This commit is contained in:
@@ -16,11 +16,15 @@ var cookie: String = ""
|
||||
fun renewCookie() : String {
|
||||
val url = "https://$hiyobi/"
|
||||
|
||||
with(URL(url).openConnection() as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
connectTimeout = 2000
|
||||
connect()
|
||||
return headerFields["Set-Cookie"]!![0]
|
||||
try {
|
||||
with(URL(url).openConnection() as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
connectTimeout = 2000
|
||||
connect()
|
||||
return headerFields["Set-Cookie"]!![0]
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,19 +34,23 @@ fun getReader(galleryId: Int) : Reader {
|
||||
if (cookie.isEmpty())
|
||||
cookie = renewCookie()
|
||||
|
||||
val json = Json(JsonConfiguration.Stable).parseJson(
|
||||
with(URL(url).openConnection() as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
setRequestProperty("Cookie", cookie)
|
||||
connectTimeout = 2000
|
||||
connect()
|
||||
try {
|
||||
val json = Json(JsonConfiguration.Stable).parseJson(
|
||||
with(URL(url).openConnection() as HttpsURLConnection) {
|
||||
setRequestProperty("User-Agent", user_agent)
|
||||
setRequestProperty("Cookie", cookie)
|
||||
connectTimeout = 2000
|
||||
connect()
|
||||
|
||||
inputStream.bufferedReader().use { it.readText() }
|
||||
inputStream.bufferedReader().use { it.readText() }
|
||||
}
|
||||
)
|
||||
|
||||
return json.jsonArray.map {
|
||||
val name = it.jsonObject["name"]!!.content
|
||||
ReaderItem("https://$hiyobi/data/$galleryId/$name", null)
|
||||
}
|
||||
)
|
||||
|
||||
return json.jsonArray.map {
|
||||
val name = it.jsonObject["name"]!!.content
|
||||
ReaderItem("https://$hiyobi/data/$galleryId/$name", null)
|
||||
} catch (e: Exception) {
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user