Skip to content

Commit

Permalink
✨ book 参数可选
Browse files Browse the repository at this point in the history
  • Loading branch information
Liloupar committed Feb 7, 2020
1 parent 177e097 commit cb62fb7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/lightink/reader/ReaderApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ReaderApplication {
private lateinit var restVerticle: RestVerticle

companion object {
fun vertx() = Vertx.vertx()
val vertx by lazy { Vertx.vertx() }
fun vertx() = vertx
}

@PostConstruct
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/lightink/reader/api/YueduApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class YueduApi : BaseApi {
it.success(YueduSchedule.Shuyuan.shuyuanlist)
}



private fun getBookInfo(context: RoutingContext) {
val bookSourceCode = context.bodyAsJson.getString("bookSourceCode")
val bookSource = if (bookSourceCode != null) {
Expand All @@ -64,7 +66,7 @@ class YueduApi : BaseApi {
} else {
context.bodyAsJson.getJsonObject("bookSource").toString()
}
val book = context.bodyAsJson.getJsonObject("book").mapTo(Book::class.java)
val book = context.bodyAsJson.getJsonObject("book")?.mapTo(Book::class.java)
val bookChapter = context.bodyAsJson.getJsonObject("bookChapter").mapTo(BookChapter::class.java)
WebBook(bookSource).getContent(book, bookChapter)
.onSuccess {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/lightink/reader/service/yuedu/WebBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import mu.KotlinLogging
import kotlin.coroutines.CoroutineContext

private val logger = KotlinLogging.logger {}

class WebBook(val bookSource: BookSource) {
Expand Down Expand Up @@ -45,7 +46,7 @@ class WebBook(val bookSource: BookSource) {
)
val currentTimeMillis = System.currentTimeMillis()
val res = analyzeUrl.getResponseAwait()
logger.info { "getResponseAwait " + (System.currentTimeMillis() - currentTimeMillis)}
logger.info { "getResponseAwait " + (System.currentTimeMillis() - currentTimeMillis) }
BookList.analyzeBookList(
res.body,
bookSource,
Expand Down Expand Up @@ -138,7 +139,7 @@ class WebBook(val bookSource: BookSource) {
* 章节内容
*/
fun getContent(
book: Book,
book: Book?,
bookChapter: BookChapter,
nextChapterUrl: String? = null,
scope: CoroutineScope = Coroutine.DEFAULT,
Expand All @@ -148,14 +149,14 @@ class WebBook(val bookSource: BookSource) {
if (bookSource.getContentRule().content.isNullOrEmpty()) {
return@async bookChapter.url
}
val body = if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
val body = if (book != null && bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
book.tocHtml
} else {
val analyzeUrl =
AnalyzeUrl(
book = book,
ruleUrl = bookChapter.url,
baseUrl = book.tocUrl,
baseUrl = book?.tocUrl,
headerMapF = bookSource.getHeaderMap()
)
analyzeUrl.getResponseAwait(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class AnalyzeUrl(
private var baseUrl: String = ""
lateinit var url: String
private set
var path: String? = null
private set
// var path: String? = null
// private set
val headerMap = HashMap<String, String>()
private var queryStr: String? = null
private val fieldMap = LinkedHashMap<String, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object BookContent {
suspend fun analyzeContent(
coroutineScope: CoroutineScope,
body: String?,
book: Book,
book: Book?,
bookChapter: BookChapter,
bookSource: BookSource,
baseUrl: String,
Expand Down Expand Up @@ -108,7 +108,7 @@ object BookContent {
private fun analyzeContent(
body: String,
contentRule: ContentRule,
book: Book,
book: Book?,
chapter: BookChapter,
bookSource: BookSource,
baseUrl: String,
Expand Down

0 comments on commit cb62fb7

Please sign in to comment.