From 6b6449f0233c9b20753dffe572ba1923105dabaf Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sat, 5 Apr 2025 20:28:56 +0800 Subject: [PATCH] mod: article: get user mid Closes #615 Signed-off-by: bggRGjQaUbCoE --- lib/http/html.dart | 24 +++++++++---- lib/pages/html/controller.dart | 2 ++ lib/pages/html/view.dart | 63 +++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/lib/http/html.dart b/lib/http/html.dart index 47dffc6f..e50a8307 100644 --- a/lib/http/html.dart +++ b/lib/http/html.dart @@ -70,8 +70,20 @@ class HtmlHttp { .split(' ')[1] .split('-'); // List imgList = opusDetail.querySelectorAll('bili-album__preview__picture__img'); + + dynamic mid; + try { + final regex = RegExp(r'window\.__INITIAL_STATE__\s*=\s*(\{.*?\});'); + final match = regex.firstMatch(response.data); + if (match != null) { + final json = jsonDecode(match.group(1)!); + mid = json['detail']['basic']['uid']; + } + } catch (_) {} + return { 'status': true, + 'mid': mid, 'avatar': avatar, 'uname': uname, 'updateTime': updateTime, @@ -115,12 +127,11 @@ class HtmlHttp { // String avatar = // authorHeader.querySelector('.bili-avatar-img')!.attributes['data-src']!; // 正则寻找形如"author":{"mid":\d+,"name":".*","face":"xxxx"的匹配项 - String avatar = - RegExp(r'"author":\{"mid":\d+?,"name":".+?","face":"(.+?)"') - .firstMatch(response.data)! - .group(1)! - .replaceAll(r'\u002F', '/') - .split('@')[0]; + final match = + RegExp(r'"author":\{"mid":(\d+)?,"name":".+?","face":"(.+?)"') + .firstMatch(response.data)!; + String mid = match.group(1)!; + String avatar = match.group(2)!.replaceAll(r'\u002F', '/').split('@')[0]; // debugPrint(avatar); String uname = authorHeader.querySelector('.up-name')!.text.trim(); // 动态详情 @@ -163,6 +174,7 @@ class HtmlHttp { String number = RegExp(r'\d+').firstMatch(id)!.group(0)!; return { 'status': true, + 'mid': mid, 'avatar': avatar, 'uname': uname, 'updateTime': '', diff --git a/lib/pages/html/controller.dart b/lib/pages/html/controller.dart index 4e01ae24..e1102bc3 100644 --- a/lib/pages/html/controller.dart +++ b/lib/pages/html/controller.dart @@ -20,6 +20,7 @@ class HtmlRenderController extends ReplyController { RxInt oid = (-1).obs; late Map response; int? floor; + dynamic mid; Rx item = DynamicItemModel().obs; @@ -77,6 +78,7 @@ class HtmlRenderController extends ReplyController { } if (res != null) { response = res; + mid = res['mid']; oid.value = res['commentId']; if (Accounts.main.isLogin && !MineController.anonymity.value) { VideoHttp.historyReport(aid: oid.value, type: 5); diff --git a/lib/pages/html/view.dart b/lib/pages/html/view.dart index 5afcc5db..afdd171c 100644 --- a/lib/pages/html/view.dart +++ b/lib/pages/html/view.dart @@ -851,35 +851,44 @@ class _HtmlRenderPageState extends State Widget get _buildHeader => Padding( padding: const EdgeInsets.fromLTRB(12, 12, 12, 8), - child: Row( - children: [ - NetworkImgLayer( - width: 40, - height: 40, - type: 'avatar', - src: _htmlRenderCtr.response['avatar']!, - ), - const SizedBox(width: 10), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - _htmlRenderCtr.response['uname'], - style: TextStyle( - fontSize: Theme.of(context).textTheme.titleSmall!.fontSize, + child: GestureDetector( + onTap: () { + if (_htmlRenderCtr.mid != null) { + Get.toNamed('/member?mid=${_htmlRenderCtr.mid}'); + } + }, + child: Row( + children: [ + NetworkImgLayer( + width: 40, + height: 40, + type: 'avatar', + src: _htmlRenderCtr.response['avatar']!, + ), + const SizedBox(width: 10), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + _htmlRenderCtr.response['uname'], + style: TextStyle( + fontSize: + Theme.of(context).textTheme.titleSmall!.fontSize, + ), ), - ), - Text( - _htmlRenderCtr.response['updateTime'], - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - fontSize: Theme.of(context).textTheme.labelSmall!.fontSize, + Text( + _htmlRenderCtr.response['updateTime'], + style: TextStyle( + color: Theme.of(context).colorScheme.outline, + fontSize: + Theme.of(context).textTheme.labelSmall!.fontSize, + ), ), - ), - ], - ), - const Spacer(), - ], + ], + ), + const Spacer(), + ], + ), ), );