From ae78c80572fc506364c50009881c5be1abe97128 Mon Sep 17 00:00:00 2001 From: 3003h Date: Fri, 1 Nov 2024 18:01:14 +0800 Subject: [PATCH] Update cookie Manage --- jsons/eh_home.json | 4 +- jsons/user.json | 1 + lib/common/parser/home_parser.dart | 38 ++++- lib/component/setting_base.dart | 12 +- lib/extension.dart | 10 +- lib/generated/intl/messages_en.dart | 2 + lib/generated/intl/messages_ja.dart | 2 + lib/generated/intl/messages_ko_KR.dart | 2 + lib/generated/intl/messages_ru.dart | 2 + lib/generated/intl/messages_zh_CN.dart | 2 + lib/generated/intl/messages_zh_TW.dart | 2 + lib/generated/l10n.dart | 10 ++ lib/l10n/intl_en.arb | 3 +- lib/l10n/intl_ja.arb | 3 +- lib/l10n/intl_ko_KR.arb | 3 +- lib/l10n/intl_ru.arb | 3 +- lib/l10n/intl_zh_CN.arb | 3 +- lib/l10n/intl_zh_TW.arb | 3 +- lib/models/eh_home.dart | 26 ++- lib/models/user.dart | 11 +- .../eh_cookie_interceptor.dart | 161 +++++++----------- lib/pages/setting/eh_setting_page.dart | 35 +++- lib/pages/setting/read_setting_page.dart | 2 +- .../setting/webview/web_mysetting_in.dart | 14 +- 24 files changed, 210 insertions(+), 144 deletions(-) diff --git a/jsons/eh_home.json b/jsons/eh_home.json index e6a8a6756..39b11f30f 100644 --- a/jsons/eh_home.json +++ b/jsons/eh_home.json @@ -1,5 +1,7 @@ { "currentLimit?": 0, "totLimit?": 5000, - "resetCost?": 100 + "resetCost?": 100, + "high-resolutionLimited?": true, + "unlockCost?": 20000 } \ No newline at end of file diff --git a/jsons/user.json b/jsons/user.json index 8934c89c2..0438f23cf 100644 --- a/jsons/user.json +++ b/jsons/user.json @@ -8,6 +8,7 @@ "sk?": "", "yay?": "", "star?": "", + "iq?": "", "avatarUrl?": "", "favcat?": "$[]favcat", "lastUptTime?": 162234 diff --git a/lib/common/parser/home_parser.dart b/lib/common/parser/home_parser.dart index 82ce2fd64..d700e1e81 100644 --- a/lib/common/parser/home_parser.dart +++ b/lib/common/parser/home_parser.dart @@ -1,3 +1,4 @@ +import 'package:eros_fe/utils/logger.dart'; import 'package:html/dom.dart'; import 'package:html/parser.dart' show parse; @@ -6,17 +7,40 @@ import '../../models/base/eh_models.dart'; EhHome parserEhHome(String response) { final Document document = parse(response); + final homeboxEml = + document.querySelector('body > div.stuffbox > div.homebox'); + logger.d('homeboxEml: ${homeboxEml?.text}'); + + final bool highResolutionLimited = + homeboxEml?.text.contains('high-resolution images can be limited') ?? + false; + final limitTextElms = document .querySelectorAll('body > div.stuffbox > div.homebox > p > strong'); - // logger.d('${limitTextElms.length}'); + logger.d('limitTextElms len: ${limitTextElms.length}'); + + logger.d('limitTextElms: ${limitTextElms.map((e) => e.text).toList()}'); + + if (limitTextElms.length < 3) { + final unlockCost = + int.tryParse(limitTextElms[0].text.replaceAll(',', '')) ?? 0; + logger.d('unlockCost: $unlockCost'); + return EhHome( + highResolutionLimited: highResolutionLimited, + unlockCost: unlockCost, + ); + } - final _currentLimit = int.tryParse(limitTextElms[0].text) ?? 0; - final _totLimit = int.tryParse(limitTextElms[1].text) ?? 5000; - final _resetCost = int.tryParse(limitTextElms[2].text) ?? 0; + final currentLimit = + int.tryParse(limitTextElms[0].text.replaceAll(',', '')) ?? 0; + final totLimit = int.tryParse(limitTextElms[1].text.replaceAll(',', '')) ?? 0; + final resetCost = + int.tryParse(limitTextElms[2].text.replaceAll(',', '')) ?? 0; return EhHome( - resetCost: _resetCost, - currentLimit: _currentLimit, - totLimit: _totLimit, + resetCost: resetCost, + currentLimit: currentLimit, + totLimit: totLimit, + highResolutionLimited: highResolutionLimited, ); } diff --git a/lib/component/setting_base.dart b/lib/component/setting_base.dart index 0c7ae85e5..ce56d99e1 100644 --- a/lib/component/setting_base.dart +++ b/lib/component/setting_base.dart @@ -905,12 +905,12 @@ Future showCustomHostEditer(BuildContext context, {int? index}) async { Future showUserCookie() async { final List _c = Global.profile.user.cookie.split(';'); - final List _cookies = + final List cookies = _c.map((e) => Cookie.fromSetCookieValue(e)).toList(); - final String _cookieString = - _cookies.map((e) => '${e.name}=${e.value}').join('\n'); - logger.d('$_cookieString '); + final String cookieString = + cookies.map((e) => '${e.name}=${e.value}').join('\n'); + logger.d('$cookieString '); return showCupertinoDialog( context: Get.context!, @@ -930,7 +930,7 @@ Future showUserCookie() async { CupertinoFormSection.insetGrouped( margin: const EdgeInsetsDirectional.fromSTEB(0, 0.0, 0, 5.0), backgroundColor: Colors.transparent, - children: _cookies + children: cookies .map((e) => CupertinoTextFormFieldRow( prefix: Text( e.name, @@ -958,7 +958,7 @@ Future showUserCookie() async { CupertinoDialogAction( child: Text(L10n.of(context).copy), onPressed: () { - Clipboard.setData(ClipboardData(text: _cookieString)); + Clipboard.setData(ClipboardData(text: cookieString)); Get.back(); showToast(L10n.of(context).copied_to_clipboard); }, diff --git a/lib/extension.dart b/lib/extension.dart index f76410660..08b0ff25d 100644 --- a/lib/extension.dart +++ b/lib/extension.dart @@ -140,7 +140,7 @@ extension ExtGalleryProvider on GalleryProvider { extension ExtUser on User { String get cookie { - final _list = [ + final cookieList = [ Cookie('ipb_member_id', memberId ?? ''), Cookie('ipb_pass_hash', passHash ?? ''), Cookie('igneous', igneous ?? ''), @@ -148,16 +148,17 @@ extension ExtUser on User { Cookie('hath_perks', hathPerks ?? ''), Cookie('star', star ?? ''), Cookie('yay', yay ?? ''), + Cookie('iq', iq ?? ''), ]; - return _list + return cookieList .whereNot((e) => e.value.isEmpty) .map((e) => '${e.name}=${e.value}') .join('; '); } List get cookies { - final _list = [ + final cookieList = [ Cookie('ipb_member_id', memberId ?? ''), Cookie('ipb_pass_hash', passHash ?? ''), Cookie('igneous', igneous ?? ''), @@ -165,9 +166,10 @@ extension ExtUser on User { Cookie('hath_perks', hathPerks ?? ''), Cookie('star', star ?? ''), Cookie('yay', yay ?? ''), + Cookie('iq', iq ?? ''), ]; - return _list.whereNot((e) => e.value.isEmpty).toList(); + return cookieList.whereNot((e) => e.value.isEmpty).toList(); } } diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 8d8cdf438..05f7ba27f 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -197,6 +197,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Hide Thumbnails"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"), + "high_resolution_images_limited": MessageLookupByLibrary.simpleMessage( + "High Resolution Images Limited"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"), "host": MessageLookupByLibrary.simpleMessage("Host"), diff --git a/lib/generated/intl/messages_ja.dart b/lib/generated/intl/messages_ja.dart index 720e79590..95aae40ae 100644 --- a/lib/generated/intl/messages_ja.dart +++ b/lib/generated/intl/messages_ja.dart @@ -172,6 +172,8 @@ class MessageLookup extends MessageLookupByLibrary { "hide_thumbnails": MessageLookupByLibrary.simpleMessage("サムネイル(非表示)"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("スクロール時にトップバーを隠す"), + "high_resolution_images_limited": MessageLookupByLibrary.simpleMessage( + "High Resolution Images Limited"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("水平サムネイル"), "host": MessageLookupByLibrary.simpleMessage("Host"), diff --git a/lib/generated/intl/messages_ko_KR.dart b/lib/generated/intl/messages_ko_KR.dart index 3b33581d3..418e8bc93 100644 --- a/lib/generated/intl/messages_ko_KR.dart +++ b/lib/generated/intl/messages_ko_KR.dart @@ -184,6 +184,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Hide Thumbnails"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"), + "high_resolution_images_limited": MessageLookupByLibrary.simpleMessage( + "High Resolution Images Limited"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"), "host": MessageLookupByLibrary.simpleMessage("Host"), diff --git a/lib/generated/intl/messages_ru.dart b/lib/generated/intl/messages_ru.dart index c9069b4a7..25a669bf0 100644 --- a/lib/generated/intl/messages_ru.dart +++ b/lib/generated/intl/messages_ru.dart @@ -202,6 +202,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Hide Thumbnails"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("Hide top bar on scroll"), + "high_resolution_images_limited": MessageLookupByLibrary.simpleMessage( + "High Resolution Images Limited"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"), "host": MessageLookupByLibrary.simpleMessage("Узел"), diff --git a/lib/generated/intl/messages_zh_CN.dart b/lib/generated/intl/messages_zh_CN.dart index 046545da6..00c05de6a 100644 --- a/lib/generated/intl/messages_zh_CN.dart +++ b/lib/generated/intl/messages_zh_CN.dart @@ -164,6 +164,8 @@ class MessageLookup extends MessageLookupByLibrary { "hide_thumbnails": MessageLookupByLibrary.simpleMessage("隐藏缩略图"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("滚动时隐藏顶栏"), + "high_resolution_images_limited": + MessageLookupByLibrary.simpleMessage("高分辨率图片限制"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("水平缩略图"), "host": MessageLookupByLibrary.simpleMessage("地址"), "hours": MessageLookupByLibrary.simpleMessage("小时"), diff --git a/lib/generated/intl/messages_zh_TW.dart b/lib/generated/intl/messages_zh_TW.dart index e2bec1047..9864ae341 100644 --- a/lib/generated/intl/messages_zh_TW.dart +++ b/lib/generated/intl/messages_zh_TW.dart @@ -172,6 +172,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Hide Thumbnails"), "hide_top_bar_on_scroll": MessageLookupByLibrary.simpleMessage("滾動時隱藏頂欄"), + "high_resolution_images_limited": MessageLookupByLibrary.simpleMessage( + "High Resolution Images Limited"), "horizontal_thumbnails": MessageLookupByLibrary.simpleMessage("Horizontal Thumbnails"), "host": MessageLookupByLibrary.simpleMessage("地址"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 2116ae53f..7f7959dbf 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -4514,6 +4514,16 @@ class L10n { args: [], ); } + + /// `High Resolution Images Limited` + String get high_resolution_images_limited { + return Intl.message( + 'High Resolution Images Limited', + name: 'high_resolution_images_limited', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 0784d73c6..1c7e9020d 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -443,5 +443,6 @@ "regex_format_error": "Regex format error", "experimental_feature": "Experimental feature", "page_view_type": "Page View Type", - "slide_out_page": "Slide Out Page" + "slide_out_page": "Slide Out Page", + "high_resolution_images_limited": "High Resolution Images Limited" } \ No newline at end of file diff --git a/lib/l10n/intl_ja.arb b/lib/l10n/intl_ja.arb index 0ff0e7a25..3acb570d3 100644 --- a/lib/l10n/intl_ja.arb +++ b/lib/l10n/intl_ja.arb @@ -443,5 +443,6 @@ "regex_format_error": "Regexフォーマットエラー", "experimental_feature": "Experimental feature", "page_view_type": "Page View Type", - "slide_out_page": "Slide Out Page" + "slide_out_page": "Slide Out Page", + "high_resolution_images_limited": "High Resolution Images Limited" } diff --git a/lib/l10n/intl_ko_KR.arb b/lib/l10n/intl_ko_KR.arb index ef2b2aad8..90a2960f2 100644 --- a/lib/l10n/intl_ko_KR.arb +++ b/lib/l10n/intl_ko_KR.arb @@ -443,5 +443,6 @@ "regex_format_error": "Regex format error", "experimental_feature": "Experimental feature", "page_view_type": "Page View Type", - "slide_out_page": "Slide Out Page" + "slide_out_page": "Slide Out Page", + "high_resolution_images_limited": "High Resolution Images Limited" } \ No newline at end of file diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 1ec950b49..336906c81 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -443,5 +443,6 @@ "regex_format_error": "Regex format error", "experimental_feature": "Experimental feature", "page_view_type": "Page View Type", - "slide_out_page": "Slide Out Page" + "slide_out_page": "Slide Out Page", + "high_resolution_images_limited": "High Resolution Images Limited" } diff --git a/lib/l10n/intl_zh_CN.arb b/lib/l10n/intl_zh_CN.arb index a6d5cd179..1fc89837f 100644 --- a/lib/l10n/intl_zh_CN.arb +++ b/lib/l10n/intl_zh_CN.arb @@ -443,5 +443,6 @@ "regex_format_error": "正则表达式格式错误", "experimental_feature": "实验性功能", "page_view_type": "页面视图类型", - "slide_out_page": "拖动返回" + "slide_out_page": "拖动返回", + "high_resolution_images_limited": "高分辨率图片限制" } \ No newline at end of file diff --git a/lib/l10n/intl_zh_TW.arb b/lib/l10n/intl_zh_TW.arb index b750dc5ac..8f3226df9 100644 --- a/lib/l10n/intl_zh_TW.arb +++ b/lib/l10n/intl_zh_TW.arb @@ -443,5 +443,6 @@ "regex_format_error": "Regex format error", "experimental_feature": "Experimental feature", "page_view_type": "Page View Type", - "slide_out_page": "Slide Out Page" + "slide_out_page": "Slide Out Page", + "high_resolution_images_limited": "High Resolution Images Limited" } diff --git a/lib/models/eh_home.dart b/lib/models/eh_home.dart index 9467b30cd..f812910f1 100644 --- a/lib/models/eh_home.dart +++ b/lib/models/eh_home.dart @@ -10,45 +10,59 @@ class EhHome { this.currentLimit, this.totLimit, this.resetCost, + this.highResolutionLimited, + this.unlockCost, }); final int? currentLimit; final int? totLimit; final int? resetCost; + final bool? highResolutionLimited; + final int? unlockCost; factory EhHome.fromJson(Map json) => EhHome( currentLimit: json['currentLimit'] != null ? int.tryParse('${json['currentLimit']}') ?? 0 : null, totLimit: json['totLimit'] != null ? int.tryParse('${json['totLimit']}') ?? 0 : null, - resetCost: json['resetCost'] != null ? int.tryParse('${json['resetCost']}') ?? 0 : null + resetCost: json['resetCost'] != null ? int.tryParse('${json['resetCost']}') ?? 0 : null, + highResolutionLimited: json['high-resolutionLimited'] != null ? bool.tryParse('${json['high-resolutionLimited']}', caseSensitive: false) ?? false : null, + unlockCost: json['unlockCost'] != null ? int.tryParse('${json['unlockCost']}') ?? 0 : null ); Map toJson() => { 'currentLimit': currentLimit, 'totLimit': totLimit, - 'resetCost': resetCost + 'resetCost': resetCost, + 'high-resolutionLimited': highResolutionLimited, + 'unlockCost': unlockCost }; EhHome clone() => EhHome( currentLimit: currentLimit, totLimit: totLimit, - resetCost: resetCost + resetCost: resetCost, + highResolutionLimited: highResolutionLimited, + unlockCost: unlockCost ); EhHome copyWith({ Optional? currentLimit, Optional? totLimit, - Optional? resetCost + Optional? resetCost, + Optional? highResolutionLimited, + Optional? unlockCost }) => EhHome( currentLimit: checkOptional(currentLimit, () => this.currentLimit), totLimit: checkOptional(totLimit, () => this.totLimit), resetCost: checkOptional(resetCost, () => this.resetCost), + highResolutionLimited: checkOptional(highResolutionLimited, () => this.highResolutionLimited), + unlockCost: checkOptional(unlockCost, () => this.unlockCost), ); @override bool operator ==(Object other) => identical(this, other) - || other is EhHome && currentLimit == other.currentLimit && totLimit == other.totLimit && resetCost == other.resetCost; + || other is EhHome && currentLimit == other.currentLimit && totLimit == other.totLimit && resetCost == other.resetCost && highResolutionLimited == other.highResolutionLimited && unlockCost == other.unlockCost; @override - int get hashCode => currentLimit.hashCode ^ totLimit.hashCode ^ resetCost.hashCode; + int get hashCode => currentLimit.hashCode ^ totLimit.hashCode ^ resetCost.hashCode ^ highResolutionLimited.hashCode ^ unlockCost.hashCode; } diff --git a/lib/models/user.dart b/lib/models/user.dart index be86e27e3..a3df788a4 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -16,6 +16,7 @@ class User { this.sk, this.yay, this.star, + this.iq, this.avatarUrl, this.favcat, this.lastUptTime, @@ -30,6 +31,7 @@ class User { final String? sk; final String? yay; final String? star; + final String? iq; final String? avatarUrl; final List? favcat; final int? lastUptTime; @@ -44,6 +46,7 @@ class User { sk: json['sk']?.toString(), yay: json['yay']?.toString(), star: json['star']?.toString(), + iq: json['iq']?.toString(), avatarUrl: json['avatarUrl']?.toString(), favcat: json['favcat'] != null ? (json['favcat'] as List? ?? []).map((e) => Favcat.fromJson(e as Map)).toList() : null, lastUptTime: json['lastUptTime'] != null ? int.tryParse('${json['lastUptTime']}') ?? 0 : null @@ -59,6 +62,7 @@ class User { 'sk': sk, 'yay': yay, 'star': star, + 'iq': iq, 'avatarUrl': avatarUrl, 'favcat': favcat?.map((e) => e.toJson()).toList(), 'lastUptTime': lastUptTime @@ -74,6 +78,7 @@ class User { sk: sk, yay: yay, star: star, + iq: iq, avatarUrl: avatarUrl, favcat: favcat?.map((e) => e.clone()).toList(), lastUptTime: lastUptTime @@ -90,6 +95,7 @@ class User { Optional? sk, Optional? yay, Optional? star, + Optional? iq, Optional? avatarUrl, Optional?>? favcat, Optional? lastUptTime @@ -103,6 +109,7 @@ class User { sk: checkOptional(sk, () => this.sk), yay: checkOptional(yay, () => this.yay), star: checkOptional(star, () => this.star), + iq: checkOptional(iq, () => this.iq), avatarUrl: checkOptional(avatarUrl, () => this.avatarUrl), favcat: checkOptional(favcat, () => this.favcat), lastUptTime: checkOptional(lastUptTime, () => this.lastUptTime), @@ -110,8 +117,8 @@ class User { @override bool operator ==(Object other) => identical(this, other) - || other is User && username == other.username && nickName == other.nickName && memberId == other.memberId && passHash == other.passHash && igneous == other.igneous && hathPerks == other.hathPerks && sk == other.sk && yay == other.yay && star == other.star && avatarUrl == other.avatarUrl && favcat == other.favcat && lastUptTime == other.lastUptTime; + || other is User && username == other.username && nickName == other.nickName && memberId == other.memberId && passHash == other.passHash && igneous == other.igneous && hathPerks == other.hathPerks && sk == other.sk && yay == other.yay && star == other.star && iq == other.iq && avatarUrl == other.avatarUrl && favcat == other.favcat && lastUptTime == other.lastUptTime; @override - int get hashCode => username.hashCode ^ nickName.hashCode ^ memberId.hashCode ^ passHash.hashCode ^ igneous.hashCode ^ hathPerks.hashCode ^ sk.hashCode ^ yay.hashCode ^ star.hashCode ^ avatarUrl.hashCode ^ favcat.hashCode ^ lastUptTime.hashCode; + int get hashCode => username.hashCode ^ nickName.hashCode ^ memberId.hashCode ^ passHash.hashCode ^ igneous.hashCode ^ hathPerks.hashCode ^ sk.hashCode ^ yay.hashCode ^ star.hashCode ^ iq.hashCode ^ avatarUrl.hashCode ^ favcat.hashCode ^ lastUptTime.hashCode; } diff --git a/lib/network/dio_interceptor/eh_cookie_interceptor/eh_cookie_interceptor.dart b/lib/network/dio_interceptor/eh_cookie_interceptor/eh_cookie_interceptor.dart index 38dcfd17a..e51b612d6 100644 --- a/lib/network/dio_interceptor/eh_cookie_interceptor/eh_cookie_interceptor.dart +++ b/lib/network/dio_interceptor/eh_cookie_interceptor/eh_cookie_interceptor.dart @@ -13,16 +13,19 @@ class EhCookieInterceptor extends Interceptor { final cookieHeader = options.headers[HttpHeaders.cookieHeader] as String? ?? ''; final cookiesString = cookieHeader.isNotEmpty ? cookieHeader : 'nw=1'; - logger.t('${options.uri} befor checkCookies:$cookiesString'); - final _cookies = cookiesString + logger.t('${options.uri} before checkCookies:$cookiesString'); + final cookies = cookiesString .split(';') .map((str) => Cookie.fromSetCookieValue(str)) .toList(); - logger.t('_cookies:$_cookies'); + logger.t('_cookies:$cookies'); - checkCookies(_cookies); - logger.t('after checkCookies:$_cookies'); - options.headers[HttpHeaders.cookieHeader] = getCookies(_cookies); + checkCookies(cookies); + logger.t('after checkCookies:$cookies'); + + saveCookieToUser(cookies); + + options.headers[HttpHeaders.cookieHeader] = getCookies(cookies); } catch (e, stack) { logger.e('$e\n$stack'); } @@ -35,7 +38,7 @@ class EhCookieInterceptor extends Interceptor { _saveCookies(response) .then((_) => super.onResponse(response, handler)) .catchError((e, StackTrace? stackTrace) { - DioError err = DioError( + DioException err = DioException( requestOptions: response.requestOptions, error: e, stackTrace: stackTrace); @@ -43,33 +46,20 @@ class EhCookieInterceptor extends Interceptor { }); } + // 保存cookie Future _saveCookies(Response response) async { - final UserController userController = Get.find(); - - final cookies = response.headers[HttpHeaders.setCookieHeader]; - - if (cookies != null) { - logger.t('set-cookie:$cookies'); - final _cookies = - cookies.map((str) => Cookie.fromSetCookieValue(str)).toList(); - logger.t('_set cookies $_cookies'); + logger.t('response.headers: ${response.headers}'); + final setCookiesFromResponse = + response.headers[HttpHeaders.setCookieHeader]; - final igneous = getCookiesValue(_cookies, 'igneous'); - final _newSk = getCookiesValue(_cookies, 'sk') ?? ''; - - userController.user(userController.user.value.copyWith( - memberId: getCookiesValue(_cookies, 'ipb_member_id')?.oN, - passHash: getCookiesValue(_cookies, 'ipb_pass_hash')?.oN, - igneous: igneous != 'mystery' && igneous != '' ? igneous?.oN : null, - hathPerks: getCookiesValue(_cookies, 'hath_perks')?.oN, - sk: _newSk.isNotEmpty ? _newSk.oN : null, - star: getCookiesValue(_cookies, 'star')?.oN, - yay: getCookiesValue(_cookies, 'yay')?.oN, - )); - - // logger.t('new sk $_newSk'); + if (setCookiesFromResponse != null) { + logger.t('set-cookie:$setCookiesFromResponse'); + final setCookies = setCookiesFromResponse + .map((str) => Cookie.fromSetCookieValue(str)) + .toList(); + logger.d('_set setCookiesFromResponse $setCookies'); - logger.t('${userController.user.value.toJson()}'); + saveCookieToUser(setCookies); } } @@ -81,12 +71,13 @@ class EhCookieInterceptor extends Interceptor { return cookies.firstWhereOrNull((e) => e.name == name)?.value; } + // 检查并处理cookie void checkCookies(List cookies) { final UserController userController = Get.find(); - final _nw = cookies.firstWhereOrNull((element) => element.name == 'nw'); - if (_nw != null) { - _nw.value = '1'; + final nw = cookies.firstWhereOrNull((element) => element.name == 'nw'); + if (nw != null) { + nw.value = '1'; } else { cookies.add(Cookie('nw', '1')); } @@ -95,78 +86,46 @@ class EhCookieInterceptor extends Interceptor { return; } - final memberId = userController.user.value.memberId; - if (memberId != null && memberId.isNotEmpty) { - final _c = cookies - .firstWhereOrNull((element) => element.name == 'ipb_member_id'); - if (_c != null) { - _c.value = memberId; - } else { - cookies.add(Cookie('ipb_member_id', memberId)); - } - } - - final passHash = userController.user.value.passHash; - if (passHash != null && passHash.isNotEmpty) { - final _c = cookies - .firstWhereOrNull((element) => element.name == 'ipb_pass_hash'); - if (_c != null) { - _c.value = passHash; - } else { - cookies.add(Cookie('ipb_pass_hash', passHash)); - } - } + final user = userController.user.value; - final igneous = userController.user.value.igneous; - if (igneous != null && igneous.isNotEmpty) { - final _c = - cookies.firstWhereOrNull((element) => element.name == 'igneous'); - if (_c != null) { - _c.value = igneous; - } else { - cookies.add(Cookie('igneous', igneous)); - } - } - - final hathPerks = userController.user.value.hathPerks; - if (hathPerks != null && hathPerks.isNotEmpty) { - final _c = - cookies.firstWhereOrNull((element) => element.name == 'hath_perks'); - if (_c != null) { - _c.value = hathPerks; - } else { - cookies.add(Cookie('hath_perks', hathPerks)); - } - } - - final sk = userController.user.value.sk; - if (sk != null && sk.isNotEmpty) { - final _c = cookies.firstWhereOrNull((element) => element.name == 'sk'); - if (_c != null) { - _c.value = sk; - } else { - cookies.add(Cookie('sk', sk)); - } - } + updateCookie(cookies, 'ipb_member_id', user.memberId); + updateCookie(cookies, 'ipb_pass_hash', user.passHash); + updateCookie(cookies, 'igneous', user.igneous); + updateCookie(cookies, 'hath_perks', user.hathPerks); + updateCookie(cookies, 'sk', user.sk); + updateCookie(cookies, 'star', user.star); + updateCookie(cookies, 'yay', user.yay); + updateCookie(cookies, 'iq', user.iq); + } - final star = userController.user.value.star; - if (star != null && star.isNotEmpty) { - final _c = cookies.firstWhereOrNull((element) => element.name == 'star'); - if (_c != null) { - _c.value = star; + void updateCookie(List cookies, String name, String? value) { + if (value != null && value.isNotEmpty) { + final tempCookie = + cookies.firstWhereOrNull((element) => element.name == name); + if (tempCookie != null) { + tempCookie.value = value; } else { - cookies.add(Cookie('star', star)); + cookies.add(Cookie(name, value)); } } + } - final yay = userController.user.value.yay; - if (yay != null && yay.isNotEmpty) { - final _c = cookies.firstWhereOrNull((element) => element.name == 'yay'); - if (_c != null) { - _c.value = yay; - } else { - cookies.add(Cookie('star', yay)); - } - } + void saveCookieToUser(List cookies) { + final UserController userController = Get.find(); + final igneous = getCookiesValue(cookies, 'igneous'); + final newSk = getCookiesValue(cookies, 'sk') ?? ''; + + userController.user(userController.user.value.copyWith( + memberId: getCookiesValue(cookies, 'ipb_member_id')?.oN, + passHash: getCookiesValue(cookies, 'ipb_pass_hash')?.oN, + igneous: igneous != 'mystery' && igneous != '' ? igneous?.oN : null, + hathPerks: getCookiesValue(cookies, 'hath_perks')?.oN, + sk: newSk.isNotEmpty ? newSk.oN : null, + star: getCookiesValue(cookies, 'star')?.oN, + yay: getCookiesValue(cookies, 'yay')?.oN, + iq: getCookiesValue(cookies, 'iq')?.oN, + )); + + logger.t('user: ${userController.user.value.toJson()}'); } } diff --git a/lib/pages/setting/eh_setting_page.dart b/lib/pages/setting/eh_setting_page.dart index 8f3313130..91ee40c8a 100644 --- a/lib/pages/setting/eh_setting_page.dart +++ b/lib/pages/setting/eh_setting_page.dart @@ -154,15 +154,36 @@ class ListViewEhSetting extends StatelessWidget { hiveHelper.setEhHome(ehHome); } } + final currentLimit = ehHome?.currentLimit ?? 0; + final totLimit = ehHome?.totLimit ?? 0; + String additionalInfoText = ''; + if (totLimit > 0) { + additionalInfoText = + '$currentLimit / $totLimit'.numberFormat; + } + String subtitleText = ''; + // if (ehHome?.highResolutionLimited ?? false) { + // subtitleText = + // L10n.of(context).high_resolution_images_limited; + // } + if (ehHome?.resetCost != null) { + if (subtitleText.isNotEmpty) { + subtitleText += '\n'; + } + subtitleText += + '${L10n.of(context).reset_cost}: ${ehHome?.resetCost ?? 0} GP' + .numberFormat; + } + return EhCupertinoListTile( title: Text(L10n.of(context).image_limits), - additionalInfo: Text(ehHome == null - ? '' - : '${ehHome.currentLimit ?? ''} / ${ehHome.totLimit ?? ''}' - .numberFormat), - subtitle: Text( - '${L10n.of(context).reset_cost}: ${ehHome?.resetCost ?? 0} GP' - .numberFormat), + additionalInfo: Text(additionalInfoText), + subtitle: subtitleText.isNotEmpty + ? Text( + subtitleText, + maxLines: 5, + ) + : null, trailing: snapshot.connectionState != ConnectionState.done ? CupertinoActivityIndicator( radius: (CupertinoTheme.of(context) diff --git a/lib/pages/setting/read_setting_page.dart b/lib/pages/setting/read_setting_page.dart index 59b43fe86..72ef86530 100644 --- a/lib/pages/setting/read_setting_page.dart +++ b/lib/pages/setting/read_setting_page.dart @@ -21,7 +21,7 @@ class ReadSettingPage extends StatelessWidget { return CupertinoPageScaffold( backgroundColor: CupertinoColors.systemGroupedBackground, navigationBar: CupertinoNavigationBar( - middle: Text(L10n.of(context).eh), + middle: Text(L10n.of(context).read_setting), ), child: CustomScrollView(slivers: [ SliverSafeArea(sliver: ReadSettingList()), diff --git a/lib/pages/setting/webview/web_mysetting_in.dart b/lib/pages/setting/webview/web_mysetting_in.dart index 714ef9e89..62856856f 100644 --- a/lib/pages/setting/webview/web_mysetting_in.dart +++ b/lib/pages/setting/webview/web_mysetting_in.dart @@ -8,6 +8,7 @@ import 'package:eros_fe/network/api.dart'; import 'package:eros_fe/pages/setting/controller/web_setting_controller.dart'; import 'package:eros_fe/utils/logger.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -26,11 +27,13 @@ class InWebMySetting extends StatelessWidget { final baseUrl = Api.getBaseUrl(); - final Map _httpHeaders = { + final Map httpHeaders = { 'Cookie': Global.profile.user.cookie, - 'host': Uri.parse(baseUrl).host, + // 'host': Uri.parse(baseUrl).host, }; + logger.d('httpHeaders: $httpHeaders'); + final CupertinoPageScaffold cpf = CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( padding: const EdgeInsetsDirectional.only(end: 6), @@ -70,7 +73,7 @@ class InWebMySetting extends StatelessWidget { url: WebUri( '$baseUrl/uconfig.php', ), - // headers: _httpHeaders, + headers: httpHeaders, ), initialSettings: inAppWebViewSettings, onWebViewCreated: (InAppWebViewController controller) { @@ -85,6 +88,11 @@ class InWebMySetting extends StatelessWidget { return NavigationActionPolicy.CANCEL; } + if (uri.path != '/uconfig.php' && kReleaseMode) { + logger.e('阻止打开 $uri'); + return NavigationActionPolicy.CANCEL; + } + return NavigationActionPolicy.ALLOW; }, onLoadStop: (InAppWebViewController controller, Uri? url) async {