Skip to content

Commit

Permalink
Fix bug that cannot parse read page in some scenarios when not logged in
Browse files Browse the repository at this point in the history
修复未登录状态下部分场景无法解析阅读页面的bug
  • Loading branch information
jiangtian616 committed Apr 20, 2024
1 parent a92ac85 commit cb83ab4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 3 additions & 1 deletion changelog/v7.5.2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- 详情页显示评论投票状态
- 修复未登录状态下部分场景无法解析阅读页面的bug

------------------------------------------------------------------------------------------

- Show comment vote status in detail page
- Show comment vote status in detail page
- Fix bug that cannot parse read page in some scenarios when not logged in
1 change: 1 addition & 0 deletions lib/src/model/image_page_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class ImagePageUrl {}
36 changes: 18 additions & 18 deletions lib/src/pages/details/details_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/config/ui_config.dart';
import 'package:jhentai/src/consts/eh_consts.dart';
import 'package:jhentai/src/database/database.dart';
import 'package:jhentai/src/extension/dio_exception_extension.dart';
import 'package:jhentai/src/extension/get_logic_extension.dart';
import 'package:jhentai/src/mixin/login_required_logic_mixin.dart';
import 'package:jhentai/src/model/gallery_comment.dart';
import 'package:jhentai/src/model/gallery_tag.dart';
import 'package:jhentai/src/model/gallery_thumbnail.dart';
import 'package:jhentai/src/model/gallery_url.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/network/eh_request.dart';
import 'package:jhentai/src/pages/download/download_base_page.dart';
Expand Down Expand Up @@ -922,38 +922,38 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To
}

Future<({GalleryDetail galleryDetails, String apikey})> _getDetailsWithRedirectAndFallback({bool useCache = true}) async {
final String? firstLink;
final String secondLink;
final GalleryUrl? firstLink;
final GalleryUrl secondLink;

/// 1. if redirect is enabled, try EH site first for EX link
/// 2. if a gallery can't be found in EH site, it may be moved into EX site
if (state.galleryUrl.url.contains(EHConsts.EXIndex)) {
if (!state.galleryUrl.isEH) {
if (EHSetting.redirect2Eh.isTrue && !_galleryOnlyInExSite()) {
firstLink = state.galleryUrl.url.replaceFirst(EHConsts.EXIndex, EHConsts.EHIndex);
secondLink = state.galleryUrl.url;
firstLink = state.galleryUrl.copyWith(isEH: true);
secondLink = state.galleryUrl;
} else {
firstLink = null;
secondLink = state.galleryUrl.url;
secondLink = state.galleryUrl;
}
} else {
/// fallback to EX site only if user has logged in
firstLink = UserSetting.hasLoggedIn() ? state.galleryUrl.url : null;
secondLink = UserSetting.hasLoggedIn() ? state.galleryUrl.url.replaceFirst(EHConsts.EHIndex, EHConsts.EXIndex) : state.galleryUrl.url;
firstLink = UserSetting.hasLoggedIn() ? state.galleryUrl : null;
secondLink = UserSetting.hasLoggedIn() ? state.galleryUrl.copyWith(isEH: false) : state.galleryUrl;
}

/// if we can't find gallery via firstLink, try second link
EHSiteException? firstException;
if (!isEmptyOrNull(firstLink)) {
if (firstLink != null) {
Log.trace('Try to find gallery via firstLink: $firstLink');
try {
({GalleryDetail galleryDetails, String apikey}) detailPageInfo = await EHRequest.requestDetailPage<({GalleryDetail galleryDetails, String apikey})>(
galleryUrl: firstLink!,
galleryUrl: firstLink.url,
parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey,
useCacheIfAvailable: useCache,
);
state.galleryUrl = state.galleryUrl.copyWith(isEH: true);
state.gallery?.galleryUrl = state.galleryUrl;
state.galleryDetails?.galleryUrl = state.galleryUrl;
state.galleryUrl = firstLink;
state.gallery?.galleryUrl = firstLink;
state.galleryDetails?.galleryUrl = firstLink;
return detailPageInfo;
} on EHSiteException catch (e) {
Log.trace('Can\'t find gallery, firstLink: $firstLink, reason: ${e.message}');
Expand All @@ -964,13 +964,13 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To
try {
Log.trace('Try to find gallery via secondLink: $secondLink');
({GalleryDetail galleryDetails, String apikey}) detailPageInfo = await EHRequest.requestDetailPage<({GalleryDetail galleryDetails, String apikey})>(
galleryUrl: secondLink,
galleryUrl: secondLink.url,
parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey,
useCacheIfAvailable: useCache,
);
state.galleryUrl = state.galleryUrl.copyWith(isEH: false);
state.gallery?.galleryUrl = state.galleryUrl;
state.galleryDetails?.galleryUrl = state.galleryUrl;
state.galleryUrl = secondLink;
state.gallery?.galleryUrl = secondLink;
state.galleryDetails?.galleryUrl = secondLink;
return detailPageInfo;
} on EHSiteException catch (e) {
Log.trace('Can\'t find gallery, secondLink: $secondLink, reason: ${e.message}');
Expand Down
5 changes: 3 additions & 2 deletions lib/src/pages/read/read_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/exception/eh_parse_exception.dart';
import 'package:jhentai/src/exception/eh_site_exception.dart';
import 'package:jhentai/src/extension/dio_exception_extension.dart';
import 'package:jhentai/src/extension/get_logic_extension.dart';
import 'package:jhentai/src/pages/read/layout/base/base_layout_logic.dart';
import 'package:jhentai/src/pages/read/layout/horizontal_double_column/horizontal_double_column_layout_logic.dart';
Expand Down Expand Up @@ -229,7 +230,7 @@ class ReadPageLogic extends GetxController {
),
maxAttempts: 3,
retryIf: (e) => e is DioException,
onRetry: (e) => Log.error('Get thumbnails error!', (e as DioException).message),
onRetry: (e) => Log.error('Get thumbnails error!', (e as DioException).errorMsg),
);
} on DioException catch (_) {
state.parseImageHrefErrorMsg = 'parsePageFailed'.tr;
Expand Down Expand Up @@ -285,7 +286,7 @@ class ReadPageLogic extends GetxController {
() => requestImage(index, reParse, reloadKey),
maxAttempts: 3,
retryIf: (e) => e is DioException,
onRetry: (e) => Log.error('Parse gallery image failed, index: ${index.toString()}', (e as DioException).message),
onRetry: (e) => Log.error('Parse gallery image failed, index: ${index.toString()}', (e as DioException).errorMsg),
);
} on DioException catch (_) {
state.parseImageUrlStates[index] = LoadingState.error;
Expand Down

0 comments on commit cb83ab4

Please sign in to comment.