diff --git a/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt b/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt index 774cf6c89..e4180fa59 100644 --- a/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt +++ b/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt @@ -1,6 +1,7 @@ package io.legado.app.data.api import kotlinx.coroutines.Deferred +import retrofit2.Call import retrofit2.Response import retrofit2.http.GET import retrofit2.http.HeaderMap @@ -26,4 +27,16 @@ interface IHttpGetApi { @HeaderMap headers: Map ): Deferred> + @GET + fun get( + @Url url: String, + @HeaderMap headers: Map + ): Call + + @GET + fun getMap( + @Url url: String, + @QueryMap(encoded = true) queryMap: Map, + @HeaderMap headers: Map + ): Call } diff --git a/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt b/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt index 166f7bfcc..0aa3ef3db 100644 --- a/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt +++ b/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt @@ -2,6 +2,7 @@ package io.legado.app.data.api import kotlinx.coroutines.Deferred import okhttp3.RequestBody +import retrofit2.Call import retrofit2.Response import retrofit2.http.* @@ -26,4 +27,19 @@ interface IHttpPostApi { @Body body: RequestBody, @HeaderMap headers: Map ): Deferred> + + @FormUrlEncoded + @POST + fun postMap( + @Url url: String, + @FieldMap(encoded = true) fieldMap: Map, + @HeaderMap headers: Map + ): Call + + @POST + fun postBody( + @Url url: String, + @Body body: RequestBody, + @HeaderMap headers: Map + ): Call } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index f3967e29c..020547d0a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.Deferred import okhttp3.FormBody import okhttp3.MediaType import okhttp3.RequestBody +import retrofit2.Call import retrofit2.Response import java.net.URLEncoder import java.util.* @@ -212,7 +213,7 @@ class AnalyzeUrl( fun getResponseAsync(): Deferred> { return when { - method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService( + method == Method.POST -> HttpHelper.getApiService( baseUrl ).postBodyAsync( url, @@ -226,4 +227,21 @@ class AnalyzeUrl( .getMapAsync(url, fieldMap, headerMap) } } + + fun getResponse(): Call { + return when { + method == Method.POST -> HttpHelper.getApiService( + baseUrl + ).postBody( + url, + body, + headerMap + ) + fieldMap.isEmpty() -> HttpHelper.getApiService( + baseUrl + ).get(url, headerMap) + else -> HttpHelper.getApiService(baseUrl) + .getMap(url, fieldMap, headerMap) + } + } } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt index 264277ccf..110cd2260 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt @@ -29,16 +29,26 @@ class BookChapterList { ) val tocRule = bookSource.getTocRule() val nextUrlList = arrayListOf(baseUrl) - val chapterData = analyzeChapterList(body, tocRule) + var chapterData = analyzeChapterList(body, tocRule) chapterList.addAll(chapterData.chapterList) if (chapterData.nextUrlList.size == 1) { var nextUrl = chapterData.nextUrlList[0] while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { nextUrlList.add(nextUrl) - + AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute() + .body()?.let { + chapterData = analyzeChapterList(it, tocRule) + nextUrl = if (chapterData.nextUrlList.isEmpty()) { + "" + } else { + chapterData.nextUrlList[0] + } + chapterList.addAll(chapterData.chapterList) + } } - } + } else if (chapterData.nextUrlList.size > 1) { + } return chapterList }