|
|
|
@ -1,12 +1,11 @@ |
|
|
|
|
package io.legado.app.model |
|
|
|
|
|
|
|
|
|
import io.legado.app.data.api.IHttpGetApi |
|
|
|
|
import io.legado.app.data.api.IHttpPostApi |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
|
import io.legado.app.help.http.HttpHelper |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
import io.legado.app.model.webbook.BookInfo |
|
|
|
|
import io.legado.app.model.webbook.BookList |
|
|
|
|
|
|
|
|
|
class WebBook(private val bookSource: BookSource) { |
|
|
|
@ -15,25 +14,19 @@ class WebBook(private val bookSource: BookSource) { |
|
|
|
|
return Coroutine.async { |
|
|
|
|
bookSource.getSearchRule().searchUrl?.let { searchUrl -> |
|
|
|
|
val analyzeUrl = AnalyzeUrl(searchUrl, key, page) |
|
|
|
|
val response = when { |
|
|
|
|
analyzeUrl.method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService<IHttpPostApi>( |
|
|
|
|
analyzeUrl.baseUrl |
|
|
|
|
).postBody( |
|
|
|
|
analyzeUrl.url, |
|
|
|
|
analyzeUrl.body, |
|
|
|
|
analyzeUrl.headerMap |
|
|
|
|
).await() |
|
|
|
|
analyzeUrl.fieldMap.isEmpty() -> HttpHelper.getApiService<IHttpGetApi>( |
|
|
|
|
analyzeUrl.baseUrl |
|
|
|
|
)[analyzeUrl.url, analyzeUrl.headerMap].await() |
|
|
|
|
else -> HttpHelper.getApiService<IHttpGetApi>(analyzeUrl.baseUrl) |
|
|
|
|
.getMap(analyzeUrl.url, analyzeUrl.fieldMap, analyzeUrl.headerMap).await() |
|
|
|
|
} |
|
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
|
return@async BookList.analyzeBookList(response, bookSource, analyzeUrl) |
|
|
|
|
} |
|
|
|
|
return@async arrayListOf<SearchBook>() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun getBookInfo(book: Book): Coroutine<Book> { |
|
|
|
|
return Coroutine.async { |
|
|
|
|
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.bookUrl) |
|
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
|
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl) |
|
|
|
|
return@async book |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |