[Lib] Authorization fixes

Zakhar Timoshenko 3 years ago
parent ad6e074cce
commit 106a85aa80

@ -110,8 +110,10 @@ internal open class MangaLibParser(
append(item.getInt("chapter_volume")) append(item.getInt("chapter_volume"))
append("/c") append("/c")
append(item.getString("chapter_number")) append(item.getString("chapter_number"))
append('/') if (isAuthorized) {
append(item.optString("chapter_string")) append("?ui=")
append(getUID())
}
} }
val nameChapter = item.getStringOrNull("chapter_name") val nameChapter = item.getStringOrNull("chapter_name")
val volume = item.getInt("chapter_volume") val volume = item.getInt("chapter_volume")
@ -233,13 +235,27 @@ internal open class MangaLibParser(
} }
override suspend fun getUsername(): String { override suspend fun getUsername(): String {
val body = context.httpGet("https://${getDomain()}/messages").parseHtml().body() val body = context.httpGet("https://${LibConst.LIB_SOCIAL_LINK}/messages").parseHtml().body()
if (body.baseUri().endsWith("/login")) { if (body.baseUri().endsWith("/login")) {
throw AuthRequiredException(source) throw AuthRequiredException(source)
} }
return body.selectFirst(".profile-user__username")?.text() ?: body.parseFailed("Cannot find username") return body.selectFirst(".profile-user__username")?.text() ?: body.parseFailed("Cannot find username")
} }
private suspend fun getUID(): String {
val url = "https://${getDomain()}/news/polzovatelskoe-soglasenie"
val body = context.httpGet(url).parseHtml().body()
val scripts = body.select("script")
for (script in scripts) {
val raw = script.html().trim()
if (raw.startsWith("window.__DATA")) {
val json = JSONObject(raw.substringAfter('=').substringBeforeLast(';'))
return json.getJSONObject("user").getInt("id").toString()
}
}
throw AuthRequiredException(source)
}
protected open fun isNsfw(doc: Document): Boolean { protected open fun isNsfw(doc: Document): Boolean {
val sidebar = doc.body().run { val sidebar = doc.body().run {
selectFirst(".media-sidebar") ?: selectFirst(".media-info") selectFirst(".media-sidebar") ?: selectFirst(".media-info")
@ -285,4 +301,10 @@ internal open class MangaLibParser(
@MangaSourceParser("MANGALIB", "MangaLib", "ru") @MangaSourceParser("MANGALIB", "MangaLib", "ru")
class Impl(context: MangaLoaderContext) : MangaLibParser(context, MangaSource.MANGALIB) class Impl(context: MangaLoaderContext) : MangaLibParser(context, MangaSource.MANGALIB)
object LibConst {
val LIB_SOCIAL_LINK = "lib.social"
}
} }
Loading…
Cancel
Save