Added Offline mode

This commit is contained in:
tom5079
2019-05-16 18:15:53 +09:00
parent 23bf93e960
commit d090a59800
14 changed files with 201 additions and 108 deletions

View File

@@ -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()
}
}