mod: article: get user mid

Closes #615

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-05 20:28:56 +08:00
parent fcf3348371
commit 6b6449f023
3 changed files with 56 additions and 33 deletions

View File

@@ -70,8 +70,20 @@ class HtmlHttp {
.split(' ')[1] .split(' ')[1]
.split('-'); .split('-');
// List imgList = opusDetail.querySelectorAll('bili-album__preview__picture__img'); // 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 { return {
'status': true, 'status': true,
'mid': mid,
'avatar': avatar, 'avatar': avatar,
'uname': uname, 'uname': uname,
'updateTime': updateTime, 'updateTime': updateTime,
@@ -115,12 +127,11 @@ class HtmlHttp {
// String avatar = // String avatar =
// authorHeader.querySelector('.bili-avatar-img')!.attributes['data-src']!; // authorHeader.querySelector('.bili-avatar-img')!.attributes['data-src']!;
// 正则寻找形如"author":{"mid":\d+,"name":".*","face":"xxxx"的匹配项 // 正则寻找形如"author":{"mid":\d+,"name":".*","face":"xxxx"的匹配项
String avatar = final match =
RegExp(r'"author":\{"mid":\d+?,"name":".+?","face":"(.+?)"') RegExp(r'"author":\{"mid":(\d+)?,"name":".+?","face":"(.+?)"')
.firstMatch(response.data)! .firstMatch(response.data)!;
.group(1)! String mid = match.group(1)!;
.replaceAll(r'\u002F', '/') String avatar = match.group(2)!.replaceAll(r'\u002F', '/').split('@')[0];
.split('@')[0];
// debugPrint(avatar); // debugPrint(avatar);
String uname = authorHeader.querySelector('.up-name')!.text.trim(); String uname = authorHeader.querySelector('.up-name')!.text.trim();
// 动态详情 // 动态详情
@@ -163,6 +174,7 @@ class HtmlHttp {
String number = RegExp(r'\d+').firstMatch(id)!.group(0)!; String number = RegExp(r'\d+').firstMatch(id)!.group(0)!;
return { return {
'status': true, 'status': true,
'mid': mid,
'avatar': avatar, 'avatar': avatar,
'uname': uname, 'uname': uname,
'updateTime': '', 'updateTime': '',

View File

@@ -20,6 +20,7 @@ class HtmlRenderController extends ReplyController {
RxInt oid = (-1).obs; RxInt oid = (-1).obs;
late Map response; late Map response;
int? floor; int? floor;
dynamic mid;
Rx<DynamicItemModel> item = DynamicItemModel().obs; Rx<DynamicItemModel> item = DynamicItemModel().obs;
@@ -77,6 +78,7 @@ class HtmlRenderController extends ReplyController {
} }
if (res != null) { if (res != null) {
response = res; response = res;
mid = res['mid'];
oid.value = res['commentId']; oid.value = res['commentId'];
if (Accounts.main.isLogin && !MineController.anonymity.value) { if (Accounts.main.isLogin && !MineController.anonymity.value) {
VideoHttp.historyReport(aid: oid.value, type: 5); VideoHttp.historyReport(aid: oid.value, type: 5);

View File

@@ -851,35 +851,44 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
Widget get _buildHeader => Padding( Widget get _buildHeader => Padding(
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8), padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
child: Row( child: GestureDetector(
children: [ onTap: () {
NetworkImgLayer( if (_htmlRenderCtr.mid != null) {
width: 40, Get.toNamed('/member?mid=${_htmlRenderCtr.mid}');
height: 40, }
type: 'avatar', },
src: _htmlRenderCtr.response['avatar']!, child: Row(
), children: [
const SizedBox(width: 10), NetworkImgLayer(
Column( width: 40,
crossAxisAlignment: CrossAxisAlignment.start, height: 40,
children: [ type: 'avatar',
Text( src: _htmlRenderCtr.response['avatar']!,
_htmlRenderCtr.response['uname'], ),
style: TextStyle( const SizedBox(width: 10),
fontSize: Theme.of(context).textTheme.titleSmall!.fontSize, Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_htmlRenderCtr.response['uname'],
style: TextStyle(
fontSize:
Theme.of(context).textTheme.titleSmall!.fontSize,
),
), ),
), Text(
Text( _htmlRenderCtr.response['updateTime'],
_htmlRenderCtr.response['updateTime'], style: TextStyle(
style: TextStyle( color: Theme.of(context).colorScheme.outline,
color: Theme.of(context).colorScheme.outline, fontSize:
fontSize: Theme.of(context).textTheme.labelSmall!.fontSize, Theme.of(context).textTheme.labelSmall!.fontSize,
),
), ),
), ],
], ),
), const Spacer(),
const Spacer(), ],
], ),
), ),
); );