Skip to content

Commit f55d1d9

Browse files
committed
Add back the setting of automatically redirecting to the EH site to deal with the problem that some IPs cannot
access the EH site 重新添加自动重定向至表站的设置,以应对部分ip无法访问表站的问题
1 parent f0a2a8d commit f55d1d9

File tree

9 files changed

+51
-9
lines changed

9 files changed

+51
-9
lines changed

changelog/v7.4.11+150.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- 偏好设置中支持搜索时将中文标签搜索结果按热度排序。感谢[e-hentai-db](https://github.com/ccloli/e-hentai-db)
22
[e-hentai-tag-count](https://github.com/poly000/e-hentai-tag-count)
3+
- 重新添加自动重定向至表站的设置,以应对部分ip无法访问表站的问题
34
- 支持自动创建.nomedia文件
45
- 支持处理下载原图时GP不足的情况
56
- 平板布局和桌面布局下,使用系统返回键返回时,会优先弹出右侧页面
@@ -29,6 +30,8 @@
2930
- In the preference settings, support to sort the Chinese tag search results by popularity when searching.
3031
Thanks to [e-hentai-db](https://github.com/ccloli/e-hentai-db)
3132
[e-hentai-tag-count](https://github.com/poly000/e-hentai-tag-count)
33+
- Add back the setting of automatically redirecting to the EH site to deal with the problem that some IPs cannot
34+
access the EH site
3235
- Support to create .nomedia file automatically
3336
- Support to process the situation of insufficient GP when downloading the original image
3437
- Under the tablet layout and desktop layout, when using the system return key to return, the right page will be

lib/src/l18n/en_US.dart

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class en_US {
227227
/// eh setting page
228228
'site': 'Site',
229229
'redirect2Eh': 'Redirect to EH if available',
230+
'redirect2EhHint': 'Try to load gallery detail page from EH site first to get better network performance',
230231
'redirectAllGallery': 'Redirect all gallery to EH',
231232
'imDonorHint': 'If you are a donor, you can turn this on to help you access gallerys in EX site',
232233
'profileSetting': 'Profile Setting',

lib/src/l18n/ko_KR.dart

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class ko_KR {
227227
/// eh setting page
228228
'site': '사이트',
229229
'redirect2Eh': '사용 가능하면 EH로 재요청',
230+
'redirect2EhHint': 'Try to load gallery detail page from EH site first to get better network performance',
230231
'redirectAllGallery': 'Redirect all gallery to EH',
231232
'imDonorHint': 'If you are a donor, you can turn this on to help you access gallerys in EX site',
232233
'profileSetting': 'Profile Setting',

lib/src/l18n/pt_BR.dart

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class pt_BR {
228228
/// eh setting page
229229
'site': 'Site',
230230
'redirect2Eh': 'Redirecionar para EH, se disponível',
231+
'redirect2EhHint': 'Try to load gallery detail page from EH site first to get better network performance',
231232
'redirectAllGallery': 'Redirect all gallery to EH',
232233
'imDonorHint': 'If you are a donor, you can turn this on to help you access gallerys in EX site',
233234
'profileSetting': 'Profile Setting',

lib/src/l18n/zh_CN.dart

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class zh_CN {
226226
/// eh setting page
227227
'site': '站点',
228228
'redirect2Eh': '优先重定向至表站',
229+
'redirect2EhHint': '优先尝试从表站加载画廊详情页,以获得更好的网络体验',
229230
'redirectAllGallery': '重定向所有画廊至表站',
230231
'imDonorHint': '如果你是捐赠者,你可以打开此项来更容易地访问里站中的画廊',
231232
'profileSetting': 'Profile设置',

lib/src/l18n/zh_TW.dart

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class zh_TW {
226226
/// eh setting page
227227
'site': '站點',
228228
'redirect2Eh': '優先重定向至表站',
229+
'redirect2EhHint': '優先嘗試從表站加載畫廊詳情頁,以獲得更好的網絡體驗',
229230
'redirectAllGallery': '重定向所有畫廊至表站',
230231
'imDonorHint': '如果你是捐赠者,你可以打開此項來更容易地訪問裏站中的畫廊',
231232
'profileSetting': 'Profile設定',

lib/src/pages/details/details_page_logic.dart

+21-8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import '../../model/tag_set.dart';
4949
import '../../service/history_service.dart';
5050
import '../../service/gallery_download_service.dart';
5151
import '../../service/storage_service.dart';
52+
import '../../setting/eh_setting.dart';
5253
import '../../setting/read_setting.dart';
5354
import '../../utils/process_util.dart';
5455
import '../../utils/route_util.dart';
@@ -720,24 +721,35 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To
720721
}
721722

722723
Future<Map<String, dynamic>> _getDetailsWithRedirectAndFallback({bool useCache = true}) async {
723-
final String firstLink;
724+
final String? firstLink;
724725
final String secondLink;
725726

726-
/// 1. Try EH site first for EX link
727+
/// 1. if redirect is enabled, try EH site first for EX link
727728
/// 2. if a gallery can't be found in EH site, it may be moved into EX site
728-
if (state.galleryUrl.contains(EHConsts.EXIndex) && !_galleryOnlyInExSite()) {
729-
firstLink = state.galleryUrl.replaceFirst(EHConsts.EXIndex, EHConsts.EHIndex);
730-
secondLink = state.galleryUrl;
729+
if (state.galleryUrl.contains(EHConsts.EXIndex)) {
730+
if (EHSetting.redirect2Eh.isTrue) {
731+
firstLink = state.galleryUrl.replaceFirst(EHConsts.EXIndex, EHConsts.EHIndex);
732+
secondLink = state.galleryUrl;
733+
} else {
734+
firstLink = null;
735+
secondLink = state.galleryUrl;
736+
}
731737
} else {
732-
firstLink = state.galleryUrl;
733-
secondLink = state.galleryUrl.replaceFirst(EHConsts.EHIndex, EHConsts.EXIndex);
738+
if (_galleryOnlyInExSite()) {
739+
firstLink = null;
740+
secondLink = state.galleryUrl.replaceFirst(EHConsts.EHIndex, EHConsts.EXIndex);
741+
} else {
742+
firstLink = state.galleryUrl;
743+
secondLink = state.galleryUrl.replaceFirst(EHConsts.EHIndex, EHConsts.EXIndex);
744+
}
734745
}
735746

736747
/// if we can't find gallery via firstLink, try second link
737748
if (!isEmptyOrNull(firstLink)) {
749+
Log.verbose('Try to find gallery via firstLink: $firstLink');
738750
try {
739751
Map<String, dynamic> galleryAndDetailAndApikey = await EHRequest.requestDetailPage<Map<String, dynamic>>(
740-
galleryUrl: firstLink,
752+
galleryUrl: firstLink!,
741753
parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey,
742754
useCacheIfAvailable: useCache,
743755
);
@@ -749,6 +761,7 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To
749761
}
750762

751763
try {
764+
Log.verbose('Try to find gallery via secondLink: $secondLink');
752765
Map<String, dynamic> galleryAndDetailAndApikey = await EHRequest.requestDetailPage<Map<String, dynamic>>(
753766
galleryUrl: secondLink,
754767
parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey,

lib/src/pages/setting/eh/setting_eh_page.dart

+13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class _SettingEHPageState extends State<SettingEHPage> {
5353
padding: const EdgeInsets.only(top: 16),
5454
children: [
5555
_buildSiteSegmentControl(),
56+
_buildRedirect2EH(),
5657
_buildProfile(),
5758
_buildSiteSetting(),
5859
_buildImageLimit(),
@@ -78,6 +79,18 @@ class _SettingEHPageState extends State<SettingEHPage> {
7879
);
7980
}
8081

82+
Widget _buildRedirect2EH() {
83+
if (EHSetting.site.value == 'EH') {
84+
return const SizedBox();
85+
}
86+
87+
return ListTile(
88+
title: Text('redirect2Eh'.tr),
89+
subtitle: Text('redirect2EhHint'.tr),
90+
trailing: Switch(value: EHSetting.redirect2Eh.value, onChanged: EHSetting.saveRedirect2Eh).fadeIn(),
91+
);
92+
}
93+
8194
Widget _buildProfile() {
8295
return ListTile(
8396
title: Text('profileSetting'.tr),

lib/src/setting/eh_setting.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import '../utils/eh_spider_parser.dart';
1515

1616
class EHSetting {
1717
static RxString site = 'EH'.obs;
18-
18+
static RxBool redirect2Eh = true.obs;
1919
static Rx<LoadingState> refreshState = LoadingState.idle.obs;
2020
static RxInt currentConsumption = (-1).obs;
2121
static RxInt totalLimit = 5000.obs;
@@ -75,6 +75,12 @@ class EHSetting {
7575
Log.info('refresh EHSetting success');
7676
}
7777

78+
static saveRedirect2Eh(bool redirect2Eh) {
79+
Log.debug('saveRedirect2Eh:$redirect2Eh');
80+
EHSetting.redirect2Eh.value = redirect2Eh;
81+
_save();
82+
}
83+
7884
static saveSite(String site) {
7985
Log.debug('saveSite:$site');
8086
EHSetting.site.value = site;
@@ -99,12 +105,14 @@ class EHSetting {
99105
static Map<String, dynamic> _toMap() {
100106
return {
101107
'site': site.value,
108+
'redirect2Eh': redirect2Eh.value,
102109
'totalLimit': totalLimit.value,
103110
};
104111
}
105112

106113
static _initFromMap(Map<String, dynamic> map) {
107114
site.value = map['site'];
115+
redirect2Eh.value = map['redirect2Eh'] ?? redirect2Eh.value;
108116
totalLimit.value = map['totalLimit'];
109117
}
110118
}

0 commit comments

Comments
 (0)