@@ -74,7 +74,7 @@ class Wenku8Repository @Inject constructor(
7474 return Result .failure(NetworkException (HttpCodeParser .parser(body.code())))
7575 } else {
7676 val html = String (body.body()!! .bytes(), Charset .forName(" GBK" ))
77- Log .d(" w_8_r" ,html)
77+ Log .d(" w_8_r" , html)
7878 val response = LoginResponse .empty()
7979 Wenku8Parser .isLoginInfoCorrect(html, response)
8080 Wenku8Parser .isLoginSuccessful(html, response)
@@ -93,11 +93,12 @@ class Wenku8Repository @Inject constructor(
9393 suspend fun getNovelByRanking (ranking : String , index : Int ): Result <NovelCoverResponse > {
9494 val requestUrl: String?
9595 val charset: String?
96- when (Locale .getDefault()) {
96+ when (Locale .getDefault()) {
9797 Locale .TRADITIONAL_CHINESE -> {
9898 requestUrl = " https://${getWenku8Node()} /modules/article/toplist.php?sort=$ranking &page=$index &charset=big5"
9999 charset = " BIG5-HKSCS"
100100 }
101+
101102 else -> {
102103 requestUrl = " https://${getWenku8Node()} /modules/article/toplist.php?sort=$ranking &page=$index &charset=gbk"
103104 charset = " GBK"
@@ -127,11 +128,12 @@ class Wenku8Repository @Inject constructor(
127128 ): Result <NovelCoverResponse > {
128129 val requestUrl: String?
129130 val charset: String?
130- when (Locale .getDefault()) {
131+ when (Locale .getDefault()) {
131132 Locale .TRADITIONAL_CHINESE -> {
132133 requestUrl = " https://${getWenku8Node()} /modules/article/tags.php?t=$category &v=$sort &page=$index &charset=big5"
133134 charset = " BIG5-HKSCS"
134135 }
136+
135137 else -> {
136138 requestUrl = " https://${getWenku8Node()} /modules/article/tags.php?t=$category &v=$sort &page=$index &charset=gbk"
137139 charset = " GBK"
@@ -157,11 +159,12 @@ class Wenku8Repository @Inject constructor(
157159 suspend fun getNovelInfo (url : String ): Result <NovelInfo > {
158160 val requestUrl: String?
159161 val charset: String?
160- when (Locale .getDefault()) {
162+ when (Locale .getDefault()) {
161163 Locale .TRADITIONAL_CHINESE -> {
162164 requestUrl = " $url &charset=big5"
163165 charset = " BIG5-HKSCS" // 不能使用普通的big5编码,不然无法显示日文
164166 }
167+
165168 else -> {
166169 requestUrl = " $url &charset=gbk"
167170 charset = " GBK"
@@ -186,11 +189,12 @@ class Wenku8Repository @Inject constructor(
186189 suspend fun getChapter (url : String ): Result <List <Volume >> {
187190 val requestUrl: String?
188191 val charset: String?
189- when (Locale .getDefault()) {
192+ when (Locale .getDefault()) {
190193 Locale .TRADITIONAL_CHINESE -> {
191194 requestUrl = " ${url} ?charset=big5"
192195 charset = " BIG5-HKSCS"
193196 }
197+
194198 else -> {
195199 requestUrl = " ${url} ?charset=gbk"
196200 charset = " GBK"
@@ -215,11 +219,12 @@ class Wenku8Repository @Inject constructor(
215219 suspend fun addNovel (aid : String ): Result <Boolean > {
216220 val requestUrl: String?
217221 val charset: String?
218- when (Locale .getDefault()) {
222+ when (Locale .getDefault()) {
219223 Locale .TRADITIONAL_CHINESE -> {
220224 requestUrl = " https://${getWenku8Node()} /modules/article/addbookcase.php?bid=$aid &charset=big5"
221225 charset = " BIG5-HKSCS"
222226 }
227+
223228 else -> {
224229 requestUrl = " https://${getWenku8Node()} /modules/article/addbookcase.php?bid=$aid &charset=gbk"
225230 charset = " GBK"
@@ -256,7 +261,7 @@ class Wenku8Repository @Inject constructor(
256261 val pairs = mutableListOf<KeyValuePair >()
257262 list.forEach { pairs.add(KeyValuePair (" checkid[]" , it, false )) }
258263 pairs.add(KeyValuePair (" classlist" , classId, false ))
259- pairs.add(KeyValuePair (" checkall" ," checkall" , false ))
264+ pairs.add(KeyValuePair (" checkall" , " checkall" , false ))
260265 pairs.add(KeyValuePair (" newclassid" , - 1 , false ))
261266 pairs.add(KeyValuePair (" classid" , classId, false ))
262267
@@ -274,7 +279,7 @@ class Wenku8Repository @Inject constructor(
274279 val pairs = mutableListOf<KeyValuePair >()
275280 list.forEach { pairs.add(KeyValuePair (" checkid[]" , it, false )) }
276281 pairs.add(KeyValuePair (" classlist" , classId, false ))
277- pairs.add(KeyValuePair (" checkall" ," checkall" , false ))
282+ pairs.add(KeyValuePair (" checkall" , " checkall" , false ))
278283 pairs.add(KeyValuePair (" newclassid" , newClassId, false ))
279284 pairs.add(KeyValuePair (" classid" , classId, false ))
280285
@@ -291,11 +296,12 @@ class Wenku8Repository @Inject constructor(
291296 suspend fun getBookshelf (classId : Int = 0): Result <Bookshelf > {
292297 val requestUrl: String?
293298 val charset: String?
294- when (Locale .getDefault()) {
299+ when (Locale .getDefault()) {
295300 Locale .TRADITIONAL_CHINESE -> {
296301 requestUrl = " https://${getWenku8Node()} /modules/article/bookcase.php?classid=$classId &charset=big5"
297302 charset = " BIG5-HKSCS"
298303 }
304+
299305 else -> {
300306 requestUrl = " https://${getWenku8Node()} /modules/article/bookcase.php?classid=$classId &charset=gbk"
301307 charset = " GBK"
@@ -319,11 +325,12 @@ class Wenku8Repository @Inject constructor(
319325 suspend fun getBookshelfFromUser (uid : String ): Result <List <SimpleNovelCover >> {
320326 val requestUrl: String?
321327 val charset: String?
322- when (Locale .getDefault()) {
328+ when (Locale .getDefault()) {
323329 Locale .TRADITIONAL_CHINESE -> {
324330 requestUrl = " https://${getWenku8Node()} /userpage.php?uid=$uid &charset=big5"
325331 charset = " BIG5-HKSCS"
326332 }
333+
327334 else -> {
328335 requestUrl = " https://${getWenku8Node()} /userpage.php?uid=$uid &charset=gbk"
329336 charset = " GBK"
@@ -348,11 +355,12 @@ class Wenku8Repository @Inject constructor(
348355 suspend fun getComment (aid : String , index : Int ): Result <CommentResponse > {
349356 val requestUrl: String?
350357 val charset: String?
351- when (Locale .getDefault()) {
358+ when (Locale .getDefault()) {
352359 Locale .TRADITIONAL_CHINESE -> {
353360 requestUrl = " https://${getWenku8Node()} /modules/article/reviews.php?aid=$aid &page=$index &charset=big5"
354361 charset = " BIG5-HKSCS"
355362 }
363+
356364 else -> {
357365 requestUrl = " https://${getWenku8Node()} /modules/article/reviews.php?aid=$aid &page=$index &charset=gbk"
358366 charset = " GBK"
@@ -377,11 +385,12 @@ class Wenku8Repository @Inject constructor(
377385 suspend fun getReply (url : String , index : Int ): Result <ReplyResponse > {
378386 val requestUrl: String?
379387 val charset: String?
380- when (Locale .getDefault()) {
388+ when (Locale .getDefault()) {
381389 Locale .TRADITIONAL_CHINESE -> {
382390 requestUrl = " $url &page=$index &charset=big5"
383391 charset = " BIG5-HKSCS"
384392 }
393+
385394 else -> {
386395 requestUrl = " $url &page=$index &charset=gbk"
387396 charset = " GBK"
@@ -405,11 +414,12 @@ class Wenku8Repository @Inject constructor(
405414 suspend fun getRecommend (): Result <List <HomeBlock >> {
406415 val requestUrl: String?
407416 val charset: String?
408- when (Locale .getDefault()) {
417+ when (Locale .getDefault()) {
409418 Locale .TRADITIONAL_CHINESE -> {
410419 requestUrl = " https://${getWenku8Node()} /index.php?charset=big5"
411420 charset = " BIG5-HKSCS"
412421 }
422+
413423 else -> {
414424 requestUrl = " https://${getWenku8Node()} /index.php?charset=gbk"
415425 charset = " GBK"
@@ -434,11 +444,12 @@ class Wenku8Repository @Inject constructor(
434444 suspend fun novelVote (aid : String ): Result <String > {
435445 val requestUrl: String?
436446 val charset: String?
437- when (Locale .getDefault()) {
447+ when (Locale .getDefault()) {
438448 Locale .TRADITIONAL_CHINESE -> {
439449 requestUrl = " https://${getWenku8Node()} /modules/article/uservote.php?id=$aid &charset=big5"
440450 charset = " BIG5-HKSCS"
441451 }
452+
442453 else -> {
443454 requestUrl = " https://${getWenku8Node()} /modules/article/uservote.php?id=$aid &charset=gbk"
444455 charset = " GBK"
@@ -463,11 +474,12 @@ class Wenku8Repository @Inject constructor(
463474 suspend fun searchNovelByTitle (title : String , index : Int ): Result <NovelCoverResponse > {
464475 val requestUrl: String?
465476 val charset: String?
466- when (Locale .getDefault()) {
477+ when (Locale .getDefault()) {
467478 Locale .TRADITIONAL_CHINESE -> {
468479 requestUrl = " https://${getWenku8Node()} /modules/article/search.php?searchtype=articlename&searchkey=$title &page=$index &charset=big5"
469480 charset = " BIG5-HKSCS"
470481 }
482+
471483 else -> {
472484 requestUrl = " https://${getWenku8Node()} /modules/article/search.php?searchtype=articlename&searchkey=$title &page=$index &charset=gbk"
473485 charset = " GBK"
@@ -499,11 +511,12 @@ class Wenku8Repository @Inject constructor(
499511 suspend fun searchNovelByAuthor (author : String , index : Int ): Result <NovelCoverResponse > {
500512 val requestUrl: String?
501513 val charset: String?
502- when (Locale .getDefault()) {
514+ when (Locale .getDefault()) {
503515 Locale .TRADITIONAL_CHINESE -> {
504516 requestUrl = " https://${getWenku8Node()} /modules/article/search.php?searchtype=author&searchkey=$author &page=$index &charset=big5"
505517 charset = " BIG5-HKSCS"
506518 }
519+
507520 else -> {
508521 requestUrl = " https://${getWenku8Node()} /modules/article/search.php?searchtype=author&searchkey=$author &page=$index &charset=gbk"
509522 charset = " GBK"
@@ -540,11 +553,12 @@ class Wenku8Repository @Inject constructor(
540553 suspend fun getUserInfo (): Result <UserInfo > {
541554 val requestUrl: String?
542555 val charset: String?
543- when (Locale .getDefault()) {
556+ when (Locale .getDefault()) {
544557 Locale .TRADITIONAL_CHINESE -> {
545558 requestUrl = " https://${getWenku8Node()} /userdetail.php?charset=big5"
546559 charset = " BIG5-HKSCS"
547560 }
561+
548562 else -> {
549563 requestUrl = " https://${getWenku8Node()} /userdetail.php?charset=gbk"
550564 charset = " GBK"
@@ -569,11 +583,12 @@ class Wenku8Repository @Inject constructor(
569583 suspend fun getCompletionNovel (index : Int ): Result <NovelCoverResponse > {
570584 val requestUrl: String?
571585 val charset: String?
572- when (Locale .getDefault()) {
586+ when (Locale .getDefault()) {
573587 Locale .TRADITIONAL_CHINESE -> {
574588 requestUrl = " https://${getWenku8Node()} /modules/article/articlelist.php?fullflag=1&page=$index &charset=big5"
575589 charset = " BIG5-HKSCS"
576590 }
591+
577592 else -> {
578593 requestUrl = " https://${getWenku8Node()} /modules/article/articlelist.php?fullflag=1&page=$index &charset=gbk"
579594 charset = " GBK"
@@ -602,11 +617,12 @@ class Wenku8Repository @Inject constructor(
602617 suspend fun isOnline (): Result <Boolean > {
603618 val requestUrl: String?
604619 val charset: String?
605- when (Locale .getDefault()) {
620+ when (Locale .getDefault()) {
606621 Locale .TRADITIONAL_CHINESE -> {
607622 requestUrl = " https://${getWenku8Node()} /index.php?&charset=big5"
608623 charset = " BIG5-HKSCS"
609624 }
625+
610626 else -> {
611627 requestUrl = " https://${getWenku8Node()} /index.php?&charset=gbk"
612628 charset = " GBK"
@@ -628,7 +644,7 @@ class Wenku8Repository @Inject constructor(
628644
629645 // 获取小说内容
630646 suspend fun getNovelContent (aid : String , cid : String ): Result <ChapterContentResponse > {
631- val requestUrl = when (Locale .getDefault()) {
647+ val requestUrl = when (Locale .getDefault()) {
632648 Locale .TRADITIONAL_CHINESE -> " action=book&do=text&aid=$aid &cid=$cid &t=1"
633649 else -> " action=book&do=text&aid=$aid &cid=$cid &t=0"
634650 }
@@ -649,7 +665,8 @@ class Wenku8Repository @Inject constructor(
649665 return Result .failure(NetworkException (ResourceUtil .getString(R .string.network_error_msg)))
650666 }
651667 }.onFailure {
652- return Result .failure(NetworkException (it.message))
668+ return if (it.stackTraceToString().contains(" 429" )) Result .failure(NetworkException (ResourceUtil .getString(R .string.http_code_429)))
669+ else Result .failure(NetworkException (it.message))
653670 }
654671 throw RuntimeException ()
655672 }
@@ -671,7 +688,8 @@ class Wenku8Repository @Inject constructor(
671688 else -> Result .success(null )
672689 }
673690 }.onFailure {
674- return Result .failure(NetworkException (it.message))
691+ return if (it.stackTraceToString().contains(" 429" )) Result .failure(NetworkException (ResourceUtil .getString(R .string.http_code_429)))
692+ else Result .failure(NetworkException (it.message))
675693 }
676694 throw RuntimeException ()
677695 }
@@ -685,7 +703,8 @@ class Wenku8Repository @Inject constructor(
685703 .awaitResult {
686704 return Result .success(null )
687705 }.onFailure {
688- return Result .failure(NetworkException (it.message))
706+ return if (it.stackTraceToString().contains(" 429" )) Result .failure(NetworkException (ResourceUtil .getString(R .string.http_code_429)))
707+ else Result .failure(NetworkException (it.message))
689708 }
690709 throw RuntimeException ()
691710 }
0 commit comments