Skip to content

Commit

Permalink
Fix archive download
Browse files Browse the repository at this point in the history
  • Loading branch information
xb2016 committed Oct 25, 2024
1 parent 4c20d27 commit 6b6279f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ object EhEngine {
suspend fun getFavoriteNote(gid: Long, token: String) = ehRequest(EhUrl.getAddFavorites(gid, token), EhUrl.getGalleryDetailUrl(gid, token))
.fetchUsingAsText(FavoritesParser::parseNote)

suspend fun downloadArchive(gid: Long, token: String, or: String, res: String, isHAtH: Boolean): String? {
suspend fun downloadArchive(gid: Long, token: String, or: String?, res: String, isHAtH: Boolean): String? {
val url = EhUrl.getDownloadArchive(gid, token, or)
val referer = EhUrl.getGalleryDetailUrl(gid, token)
val request = ehRequest(url, referer, EhUrl.origin) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/hippo/ehviewer/client/EhUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ object EhUrl {
addQueryParameter("act", "addfav")
}.buildString()

fun getDownloadArchive(gid: Long, token: String, or: String) = ehUrl("archiver.php") {
fun getDownloadArchive(gid: Long, token: String, or: String?) = ehUrl("archiver.php") {
addQueryParameter("gid", "$gid")
addQueryParameter("token", token)
addQueryParameter("or", or)
addQueryParameterIfNotBlank("or", or)
}.buildString()

fun getTagDefinitionUrl(tag: String) = "https://ehwiki.org/wiki/" + tag.replace(' ', '_')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ object ArchiveParser {
"You do not have enough funds to download this archive."

fun parse(body: String, maybeFunds: Funds?): Result {
val m = PATTERN_HATH_FORM.find(body)!!
val paramOr = m.groupValues[1]
val paramOr = PATTERN_HATH_FORM.find(body)?.groupValues[1]
val archiveList = ArrayList<Archive>()
Jsoup.parse(body).select("#db>div>div").forEach { element ->
if (element.childrenSize() > 0 && !element.attr("style").contains("color:#CCCCCC")) {
Expand Down Expand Up @@ -78,7 +77,7 @@ object ArchiveParser {
// TODO: Check more errors
}

data class Result(val paramOr: String, val archiveList: List<Archive>, val funds: Funds)
data class Result(val paramOr: String?, val archiveList: List<Archive>, val funds: Funds)
}

class Archive(
Expand Down

0 comments on commit 6b6279f

Please sign in to comment.