From 443c3af5d98b552c784f1dcf53a09deac0aed729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=85=B1=E5=A4=A9=E5=B0=8F=E7=A6=BD=E5=85=BD?= Date: Tue, 5 Apr 2022 22:50:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=94=AF=E6=8C=81=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=9C=80=E5=90=8E=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8E=92=E8=A1=8C=E6=A6=9C=E5=92=8C?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E7=9A=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/l18n/en_US.dart | 2 + lib/src/l18n/zh_CN.dart | 5 +- lib/src/model/gallery_comment.dart | 3 +- lib/src/pages/details/widget/eh_comment.dart | 10 +++- .../gallerys/gallerys_view_logic.dart | 17 +++--- .../ranklist/ranklist_view_logic.dart | 23 +++++--- lib/src/utils/eh_spider_parser.dart | 54 +++++++++++++------ 7 files changed, 80 insertions(+), 34 deletions(-) diff --git a/lib/src/l18n/en_US.dart b/lib/src/l18n/en_US.dart index 71b2c6ea..0660c1ec 100644 --- a/lib/src/l18n/en_US.dart +++ b/lib/src/l18n/en_US.dart @@ -68,6 +68,7 @@ class en_US { 'uploader': 'Uploader', 'allComments': 'All Comments', 'noComments': 'No Comments', + 'lastEditedOn': 'Last edited on', 'getGalleryDetailFailed': 'Get Gallery Detail Failed', 'invisible2User': 'This Gallery is invisible to You', 'invisibleHints': 'This gallery is removed or unavailable.', @@ -196,6 +197,7 @@ class en_US { /// ranklist view 'getRanklistFailed': 'Get Ranklist Failed', + 'getSomeOfGallerysFailed': 'Get Some of Gallerys Failed', /// history view 'getHistoryGallerysFailed': 'Get Some of History Gallerys Failed', diff --git a/lib/src/l18n/zh_CN.dart b/lib/src/l18n/zh_CN.dart index 0750b47b..add5d5b2 100644 --- a/lib/src/l18n/zh_CN.dart +++ b/lib/src/l18n/zh_CN.dart @@ -68,6 +68,7 @@ class zh_CN { 'uploader': '上传者', 'allComments': '所有评论', 'noComments': '暂无评论', + 'lastEditedOn': '最后修改于', 'getGalleryDetailFailed': '获取画廊详情失败', 'invisible2User': '此画廊对您不可见', 'invisibleHints': '画廊已被删除或对您进行了限制', @@ -195,9 +196,11 @@ class zh_CN { /// ranklist view 'getRanklistFailed': '获取排行榜数据失败', + 'getSomeOfGallerysFailed': '获取部分画廊数据失败', /// history view - 'getHistoryGallerysFailed': '获取部分历史数据失败', + 'getHistoryGallerysFailed': '获取历史数据失败', + /// search page 'search': '搜索', diff --git a/lib/src/model/gallery_comment.dart b/lib/src/model/gallery_comment.dart index da36fab7..87bc7ca4 100644 --- a/lib/src/model/gallery_comment.dart +++ b/lib/src/model/gallery_comment.dart @@ -4,6 +4,7 @@ class GalleryComment { String score; String content; String time; + String? lastEditTime; GalleryComment({ required this.id, @@ -11,6 +12,6 @@ class GalleryComment { required this.score, required this.content, required this.time, + this.lastEditTime, }); - } diff --git a/lib/src/pages/details/widget/eh_comment.dart b/lib/src/pages/details/widget/eh_comment.dart index c88b8d73..f9b29471 100644 --- a/lib/src/pages/details/widget/eh_comment.dart +++ b/lib/src/pages/details/widget/eh_comment.dart @@ -97,8 +97,16 @@ class _EHCommentState extends State { factoryBuilder: () => _WidgetFactoryWithTextMaxLine(), ).marginOnly(top: 2, bottom: 14), Row( - mainAxisAlignment: MainAxisAlignment.end, children: [ + if (widget.comment.lastEditTime != null) + Text( + '${'lastEditedOn'.tr}: ${widget.comment.lastEditTime}', + style: TextStyle( + fontSize: 9, + color: Colors.grey.shade600, + ), + ), + const Expanded(child: SizedBox()), if (widget.comment.score.isNotEmpty) LikeButton( size: 18, diff --git a/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart b/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart index 01a08997..fd5e96c6 100644 --- a/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart +++ b/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart @@ -235,16 +235,21 @@ class GallerysViewLogic extends GetxController with GetTickerProviderStateMixin galleryUrls .mapIndexed( (index, url) => EHRequest.requestDetailPage(galleryUrl: url, parser: EHSpiderParser.detailPage2Gallery) - .then((value) => gallerys[index] = value), + .then((value) => gallerys[index] = value) + .catchError((error) { + /// 404 => hide or remove + if (error.response?.statusCode != 404) { + Log.error('${'getHistoryGallerysFailed'.tr}:$url', error.message); + } else { + Log.info('Gallery 404: $url', false); + } + throw error; + }), ) .toList(), ); } on DioError catch (e) { - /// 404 => hide or remove - if (e.response?.statusCode != 404) { - Log.error('getHistoryGallerysFailed'.tr, e.message); - snack('getHistoryGallerysFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM); - } + snack('getSomeOfGallerysFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM); } gallerys.removeWhere((r) => r == null); diff --git a/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart b/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart index 2253ef45..f8f29299 100644 --- a/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart +++ b/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart @@ -59,18 +59,25 @@ class RanklistViewLogic extends GetxController { (index, baseGallery) => EHRequest.requestDetailPage>( galleryUrl: baseGallery.galleryUrl, parser: EHSpiderParser.detailPage2GalleryAndDetailAndApikey, - ).then( - (value) => results[index] = value, - ), + ).then((value) => results[index] = value).catchError((error) { + /// 404 => hide or remove + if (error.response?.statusCode != 404) { + Log.error('${'getRanklistFailed'.tr}: ${baseGallery.galleryUrl}', error.message); + } else { + Log.info('Gallery 404: ${baseGallery.galleryUrl}', false); + } + throw error; + }), ) .toList(), ); } on DioError catch (e) { - /// 404 => hide or remove - if (e.response?.statusCode != 404) { - Log.error('getRanklistFailed'.tr, e.message); - snack('getRanklistFailed'.tr, e.message, longDuration: true, snackPosition: SnackPosition.BOTTOM); - } + snack( + 'getSomeOfGallerysFailed'.tr, + e.message, + longDuration: true, + snackPosition: SnackPosition.BOTTOM, + ); } results.removeWhere((r) => r == null); diff --git a/lib/src/utils/eh_spider_parser.dart b/lib/src/utils/eh_spider_parser.dart index 4ff7fb5d..a827e3d4 100644 --- a/lib/src/utils/eh_spider_parser.dart +++ b/lib/src/utils/eh_spider_parser.dart @@ -713,23 +713,43 @@ class EHSpiderParser { } static List _parseGalleryDetailsComments(List commentElements) { - return commentElements.map((element) { - /// eg: 'Posted on 10 March 2022, 03:49 by: hibiki' - String timeDesc = element.querySelector('.c2 > .c3')?.text ?? ''; - - /// eg: '10 March 2022, 03:49' - String timeString = RegExp(r'Posted on (.+, .+) by:').firstMatch(timeDesc)?.group(1) ?? ''; - final DateTime utcTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(timeString).toLocal(); - final String localTime = DateFormat('yyyy-MM-dd HH:mm').format(utcTime); - - return GalleryComment( - id: int.parse(element.querySelector('.c6')?.attributes['id']?.split('_')[1] ?? ''), - userName: element.querySelector('.c2 > .c3')?.children[0].text ?? '', - score: element.querySelector('.c2 > .c5.nosel > span')?.text ?? '', - content: element.querySelector('.c6')?.outerHtml ?? '', - time: localTime, - ); - }).toList(); + return commentElements + .map( + (element) => GalleryComment( + id: int.parse(element.querySelector('.c6')?.attributes['id']?.split('_')[1] ?? ''), + userName: element.querySelector('.c2 > .c3')?.children[0].text ?? '', + score: element.querySelector('.c2 > .c5.nosel > span')?.text ?? '', + content: element.querySelector('.c6')?.outerHtml ?? '', + time: _parsePostedLocalTime(element), + lastEditTime: _parsePostedEditedTime(element), + ), + ) + .toList(); + } + + static String _parsePostedLocalTime(Element element) { + /// eg: 'Posted on 10 March 2022, 03:49 by: hibiki' + String postedTimeDesc = element.querySelector('.c2 > .c3')?.text ?? ''; + + /// eg: '10 March 2022, 03:49' + String postedTimeString = RegExp(r'Posted on (.+, .+) by:').firstMatch(postedTimeDesc)?.group(1) ?? ''; + final DateTime postedUTCTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(postedTimeString).toLocal(); + final String postedLocalTime = DateFormat('yyyy-MM-dd HH:mm').format(postedUTCTime); + + return postedLocalTime; + } + + static String? _parsePostedEditedTime(Element element) { + /// eg: '10 March 2022, 03:49' + String? postedTimeString = element.querySelector('.c8 > strong')?.text; + if (postedTimeString == null) { + return null; + } + + final DateTime postedUTCTime = DateFormat('dd MMMM yyyy, HH:mm', 'en_US').parseUtc(postedTimeString).toLocal(); + final String postedLocalTime = DateFormat('yyyy-MM-dd HH:mm').format(postedUTCTime); + + return postedLocalTime; } static List _parseGalleryDetailsSmallThumbnails(List thumbNailElements) {