From 5940c4f0327d6e049cc72636f542a86ccef833af Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 30 Apr 2025 20:52:43 +0800 Subject: [PATCH] opt: get blockserver Signed-off-by: bggRGjQaUbCoE --- lib/http/live.dart | 2 +- lib/pages/video/detail/controller.dart | 9 +++++---- .../video/detail/post_panel/post_panel.dart | 16 ++++++++++++---- lib/utils/request_utils.dart | 13 ++++++++----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/http/live.dart b/lib/http/live.dart index 8d3f82c0..80cb7fa1 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -35,7 +35,7 @@ class LiveHttp { 'origin': 'https://live.bilibili.com', 'referer': 'https://live.bilibili.com/', 'user-agent': Request.headerUa(type: 'pc'), - if (gaiaVtoken == null) 'cookie': 'x-bili-gaia-vtoken=$gaiaVtoken' + if (gaiaVtoken != null) 'cookie': 'x-bili-gaia-vtoken=$gaiaVtoken' }, ), ); diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index da26b39e..5d39571d 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -460,6 +460,7 @@ class VideoDetailController extends GetxController Color _getColor(SegmentType segment) => _blockColor?[segment.index] ?? segment.color; late RxString videoLabel = ''.obs; + late final blockServer = GStorage.blockServer; Timer? skipTimer; late final listKey = GlobalKey(); @@ -467,7 +468,7 @@ class VideoDetailController extends GetxController Future _vote(String uuid, int type) async { Request().post( - '${GStorage.blockServer}/api/voteOnSponsorTime', + '$blockServer/api/voteOnSponsorTime', queryParameters: { 'UUID': uuid, 'userID': GStorage.blockUserID, @@ -493,7 +494,7 @@ class VideoDetailController extends GetxController onTap: () { Get.back(); Request().post( - '${GStorage.blockServer}/api/voteOnSponsorTime', + '$blockServer/api/voteOnSponsorTime', queryParameters: { 'UUID': segment.UUID, 'userID': GStorage.blockUserID, @@ -693,7 +694,7 @@ class VideoDetailController extends GetxController segmentList.clear(); segmentProgressList = null; final result = await Request().get( - '${GStorage.blockServer}/api/skipSegments', + '$blockServer/api/skipSegments', queryParameters: { 'videoID': bvid, 'cid': cid.value, @@ -936,7 +937,7 @@ class VideoDetailController extends GetxController } if (GStorage.blockTrack) { Request().post( - '${GStorage.blockServer}/api/viewedVideoSponsorTime', + '$blockServer/api/viewedVideoSponsorTime', queryParameters: {'UUID': item.UUID}, ); } diff --git a/lib/pages/video/detail/post_panel/post_panel.dart b/lib/pages/video/detail/post_panel/post_panel.dart index 8cf25264..433e9b7d 100644 --- a/lib/pages/video/detail/post_panel/post_panel.dart +++ b/lib/pages/video/detail/post_panel/post_panel.dart @@ -535,9 +535,10 @@ class _PostPanelState extends CommonCollapseSlidePageState { ]; } - Future _onPost({String? url}) { - return Request().post( - url ?? '${GStorage.blockServer}/api/skipSegments', + void _onPost() { + Request() + .post( + '${widget.videoDetailController.blockServer}/api/skipSegments', data: { 'videoID': videoDetailController.bvid, 'cid': videoDetailController.cid.value.toString(), @@ -557,7 +558,14 @@ class _PostPanelState extends CommonCollapseSlidePageState { ) .toList(), }, - options: Options(followRedirects: true), + options: Options( + followRedirects: true, // Defaults to true. + validateStatus: (int? status) { + return (status! >= 200 && status < 300) || + const [400, 403, 429, 409] // reduce extra toast + .contains(status); + }, + ), ) .then( (res) { diff --git a/lib/utils/request_utils.dart b/lib/utils/request_utils.dart index f0965abd..474f204b 100644 --- a/lib/utils/request_utils.dart +++ b/lib/utils/request_utils.dart @@ -491,11 +491,14 @@ class RequestUtils { token: captchaData.token, validate: captchaData.validate, ); - if (res['status'] && res['data']?['is_valid'] == 1) { - // onSuccess(captchaData.token!); - final griskId = res['data']?['grisk_id']; - if (griskId != null) { - onSuccess(griskId); + if (res['status']) { + if (res['data']?['is_valid'] == 1) { + final griskId = res['data']?['grisk_id']; + if (griskId != null) { + onSuccess(griskId); + } + } else { + SmartDialog.showToast('invalid'); } } else { SmartDialog.showToast(res['msg']);