From 9e93b50860ac997d789fe963dc4113fec5168a71 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 31 Jan 2024 22:33:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?mod:=20=E8=BF=98=E5=8E=9Faid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/reply.dart | 4 ++-- lib/http/video.dart | 2 +- lib/pages/bangumi/introduction/controller.dart | 2 +- lib/pages/dynamics/detail/view.dart | 4 ++-- lib/pages/html/view.dart | 3 +-- lib/pages/video/detail/introduction/controller.dart | 2 +- lib/pages/video/detail/reply/controller.dart | 6 +++--- lib/pages/video/detail/reply/view.dart | 7 +++---- lib/pages/video/detail/reply/widgets/reply_item.dart | 2 +- lib/pages/video/detail/reply_new/view.dart | 2 +- 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/http/reply.dart b/lib/http/reply.dart index 4c165b3b..fab433fc 100644 --- a/lib/http/reply.dart +++ b/lib/http/reply.dart @@ -4,7 +4,7 @@ import 'init.dart'; class ReplyHttp { static Future replyList({ - required dynamic oid, + required int oid, required int pageNum, required int type, int? ps, @@ -76,7 +76,7 @@ class ReplyHttp { // 评论点赞 static Future likeReply({ required int type, - required dynamic oid, + required int oid, required int rpid, required int action, }) async { diff --git a/lib/http/video.dart b/lib/http/video.dart index 7929be63..923e93a2 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -331,7 +331,7 @@ class VideoHttp { // plat num 发送平台标识 非必要 1:web端 2:安卓客户端 3:ios客户端 4:wp客户端 static Future replyAdd({ required ReplyType type, - required dynamic oid, + required int oid, required String message, int? root, int? parent, diff --git a/lib/pages/bangumi/introduction/controller.dart b/lib/pages/bangumi/introduction/controller.dart index 695bca3a..13dd50c0 100644 --- a/lib/pages/bangumi/introduction/controller.dart +++ b/lib/pages/bangumi/introduction/controller.dart @@ -266,7 +266,7 @@ class BangumiIntroController extends GetxController { /// 未渲染回复组件时可能异常 VideoReplyController videoReplyCtr = Get.find(tag: Get.arguments['heroTag']); - videoReplyCtr.oid = bvid; + videoReplyCtr.aid = aid; videoReplyCtr.queryReplyList(type: 'init'); } catch (_) {} } diff --git a/lib/pages/dynamics/detail/view.dart b/lib/pages/dynamics/detail/view.dart index 9489346f..840cd33f 100644 --- a/lib/pages/dynamics/detail/view.dart +++ b/lib/pages/dynamics/detail/view.dart @@ -385,8 +385,8 @@ class _DynamicDetailPageState extends State isScrollControlled: true, builder: (BuildContext context) { return VideoReplyNewDialog( - oid: _dynamicDetailController.oid?.toString() ?? - Get.parameters['bvid'], + oid: _dynamicDetailController.oid ?? + IdUtils.bv2av(Get.parameters['bvid']!), root: 0, parent: 0, replyType: ReplyType.values[replyType], diff --git a/lib/pages/html/view.dart b/lib/pages/html/view.dart index 7625306f..9f0c865c 100644 --- a/lib/pages/html/view.dart +++ b/lib/pages/html/view.dart @@ -13,7 +13,6 @@ import 'package:pilipala/pages/video/detail/reply/widgets/reply_item.dart'; import 'package:pilipala/pages/video/detail/reply_new/index.dart'; import 'package:pilipala/pages/video/detail/reply_reply/index.dart'; import 'package:pilipala/utils/feed_back.dart'; -import 'package:pilipala/utils/id_utils.dart'; import 'controller.dart'; @@ -428,7 +427,7 @@ class _HtmlRenderPageState extends State isScrollControlled: true, builder: (BuildContext context) { return VideoReplyNewDialog( - oid: IdUtils.av2bv(_htmlRenderCtr.oid.value), + oid: _htmlRenderCtr.oid.value, root: 0, parent: 0, replyType: ReplyType.values[type], diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 73165117..1230a94b 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -478,7 +478,7 @@ class VideoIntroController extends GetxController { /// 未渲染回复组件时可能异常 final VideoReplyController videoReplyCtr = Get.find(tag: heroTag); - videoReplyCtr.oid = bvid; + videoReplyCtr.aid = aid; videoReplyCtr.queryReplyList(type: 'init'); } catch (_) {} this.bvid = bvid; diff --git a/lib/pages/video/detail/reply/controller.dart b/lib/pages/video/detail/reply/controller.dart index 03c5fb0e..9e05542b 100644 --- a/lib/pages/video/detail/reply/controller.dart +++ b/lib/pages/video/detail/reply/controller.dart @@ -11,13 +11,13 @@ import 'package:pilipala/utils/storage.dart'; class VideoReplyController extends GetxController { VideoReplyController( - this.oid, + this.aid, this.rpid, this.replyLevel, ); final ScrollController scrollController = ScrollController(); // 视频aid 请求时使用的oid - String? oid; + int? aid; // 层级 2为楼中楼 String? replyLevel; // rpid 请求楼中楼回复 @@ -57,7 +57,7 @@ class VideoReplyController extends GetxController { return; } final res = await ReplyHttp.replyList( - oid: oid!, + oid: aid!, pageNum: currentPage + 1, ps: ps, type: ReplyType.video.index, diff --git a/lib/pages/video/detail/reply/view.dart b/lib/pages/video/detail/reply/view.dart index 474615fc..b2c67b1e 100644 --- a/lib/pages/video/detail/reply/view.dart +++ b/lib/pages/video/detail/reply/view.dart @@ -40,7 +40,6 @@ class _VideoReplyPanelState extends State bool _isFabVisible = true; String replyLevel = '1'; late String heroTag; - late String oid; // 添加页面缓存 @override @@ -49,7 +48,7 @@ class _VideoReplyPanelState extends State @override void initState() { super.initState(); - oid = widget.bvid != null ? widget.bvid! : '0'; + int oid = widget.bvid != null ? IdUtils.bv2av(widget.bvid!) : 0; heroTag = Get.arguments['heroTag']; replyLevel = widget.replyLevel ?? '1'; if (replyLevel == '2') { @@ -298,8 +297,8 @@ class _VideoReplyPanelState extends State isScrollControlled: true, builder: (BuildContext context) { return VideoReplyNewDialog( - oid: - _videoReplyController.oid ?? Get.parameters['bvid'], + oid: _videoReplyController.aid ?? + IdUtils.bv2av(Get.parameters['bvid']!), root: 0, parent: 0, replyType: ReplyType.video, diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 3352cdc3..48518bee 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -353,7 +353,7 @@ class ReplyItem extends StatelessWidget { isScrollControlled: true, builder: (builder) { return VideoReplyNewDialog( - oid: IdUtils.av2bv(replyItem!.oid!), + oid: replyItem!.oid, root: replyItem!.rpid, parent: replyItem!.rpid, replyType: replyType, diff --git a/lib/pages/video/detail/reply_new/view.dart b/lib/pages/video/detail/reply_new/view.dart index 61a78869..01c95adc 100644 --- a/lib/pages/video/detail/reply_new/view.dart +++ b/lib/pages/video/detail/reply_new/view.dart @@ -8,7 +8,7 @@ import 'package:pilipala/models/video/reply/item.dart'; import 'package:pilipala/utils/feed_back.dart'; class VideoReplyNewDialog extends StatefulWidget { - final String? oid; + final int? oid; final int? root; final int? parent; final ReplyType? replyType; From d703e38c3fd9599f08cd37f31a22f0e8fcd5afb3 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 31 Jan 2024 22:43:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20avbv=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/id_utils.dart | 79 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/lib/utils/id_utils.dart b/lib/utils/id_utils.dart index a68bfb40..d0451b17 100644 --- a/lib/utils/id_utils.dart +++ b/lib/utils/id_utils.dart @@ -1,51 +1,52 @@ -// ignore_for_file: constant_identifier_names +// ignore_for_file: constant_identifier_names, non_constant_identifier_names import 'dart:convert'; -import 'dart:math'; - -import 'package:flutter/material.dart'; class IdUtils { - static const String TABLE = - 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'; - static const List S = [11, 10, 3, 8, 4, 6]; // 位置编码表 - static const int XOR = 177451812; // 固定异或值 - static const int ADD = 8728348608; // 固定加法值 - static const List r = [ - 'B', - 'V', - '1', - '', - '', - '4', - '', - '1', - '', - '7', - '', - '' - ]; + static final XOR_CODE = BigInt.parse('23442827791579'); + static final MASK_CODE = BigInt.parse('2251799813685247'); + static final MAX_AID = BigInt.one << (BigInt.from(51)).toInt(); + static final BASE = BigInt.from(58); + + static const data = + 'FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf'; /// av转bv - static String av2bv(int av) { - int x_ = (av ^ XOR) + ADD; - List newR = []; - newR.addAll(r); - for (int i = 0; i < S.length; i++) { - newR[S[i]] = - TABLE.characters.elementAt((x_ / pow(58, i).toInt() % 58).toInt()); + static String av2bv(int aid) { + List bytes = List.filled(12, '0', growable: false); + int bvIndex = bytes.length - 1; + BigInt tmp = (MAX_AID | BigInt.from(aid)) ^ XOR_CODE; + while (tmp > BigInt.zero) { + bytes[bvIndex] = data[(tmp % BASE).toInt()]; + tmp = tmp ~/ BASE; + bvIndex -= 1; } - return newR.join(); + final tmpValue = bytes[3]; + bytes[3] = bytes[9]; + bytes[9] = tmpValue; + + final tmpValue2 = bytes[4]; + bytes[4] = bytes[7]; + bytes[7] = tmpValue2; + + return bytes.join(); } - /// bv转bv - static int bv2av(String bv) { - int r = 0; - for (int i = 0; i < S.length; i++) { - r += (TABLE.indexOf(bv.characters.elementAt(S[i])).toInt()) * - pow(58, i).toInt(); - } - return (r - ADD) ^ XOR; + /// bv转av + static int bv2av(String bvid) { + List bvidArr = bvid.split(''); + final tmpValue = bvidArr[3]; + bvidArr[3] = bvidArr[9]; + bvidArr[9] = tmpValue; + + final tmpValue2 = bvidArr[4]; + bvidArr[4] = bvidArr[7]; + bvidArr[7] = tmpValue2; + + bvidArr.removeRange(0, 3); + BigInt tmp = bvidArr.fold(BigInt.zero, + (pre, bvidChar) => pre * BASE + BigInt.from(data.indexOf(bvidChar))); + return ((tmp & MASK_CODE) ^ XOR_CODE).toInt(); } // 匹配