From 6ea8ffea7afe93362fb0323e3d08171d0898c46d Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sat, 29 Mar 2025 10:56:35 +0800 Subject: [PATCH] opt: note Signed-off-by: bggRGjQaUbCoE --- lib/http/api.dart | 2 + lib/http/init.dart | 18 +++++---- lib/http/video.dart | 5 ++- lib/pages/fav/note/controller.dart | 6 ++- .../video/detail/note/note_list_page.dart | 1 + lib/pages/webview/webview_page.dart | 39 +++++++++++++------ 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/http/api.dart b/lib/http/api.dart index e4a18342..fcd1a48e 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -735,5 +735,7 @@ class Api { static const String delNote = '/x/note/del'; + static const String delPublishNote = '/x/note/publish/del'; + static const String archiveNote = '/x/note/list/archive'; } diff --git a/lib/http/init.dart b/lib/http/init.dart index ed723317..75f13dd7 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -270,13 +270,17 @@ class Request { } static String headerUa({type = 'mob'}) { - return type == 'mob' - ? Platform.isIOS - ? 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 BiliApp/62000200' - : 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36' - : type == 'ios' - ? 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 BiliApp/62000200' - : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15'; + return switch (type) { + 'mob' => Platform.isIOS + ? 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 BiliApp/62000200' + : 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36', + 'android' => + 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36', + 'ios' => + 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 BiliApp/62000200', + _ => + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15' + }; } static String responseDecoder(List responseBytes, RequestOptions options, diff --git a/lib/http/video.dart b/lib/http/video.dart index 69e072ac..b92e32b0 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -1176,12 +1176,13 @@ class VideoHttp { } static Future delNote({ + required bool isPublish, required List noteIds, }) async { final res = await Request().post( - Api.delNote, + isPublish ? Api.delPublishNote : Api.delNote, data: { - 'note_ids': noteIds.join(','), + isPublish ? 'cvids' : 'note_ids': noteIds.join(','), 'csrf': Accounts.main.csrf, }, options: Options( diff --git a/lib/pages/fav/note/controller.dart b/lib/pages/fav/note/controller.dart index 77cd4f18..e5d9b6e4 100644 --- a/lib/pages/fav/note/controller.dart +++ b/lib/pages/fav/note/controller.dart @@ -53,7 +53,11 @@ class FavNoteController extends MultiSelectController { List dataList = (loadingState.value as Success).response as List; Set removeList = dataList.where((item) => item['checked'] == true).toSet(); final res = await VideoHttp.delNote( - noteIds: removeList.map((item) => item['note_id']).toList()); + isPublish: isPublish, + noteIds: removeList + .map((item) => isPublish ? item['cvid'] : item['note_id']) + .toList(), + ); if (res['status']) { List remainList = dataList.toSet().difference(removeList).toList(); loadingState.value = LoadingState.success(remainList); diff --git a/lib/pages/video/detail/note/note_list_page.dart b/lib/pages/video/detail/note/note_list_page.dart index 33eeae8c..4e3dccf3 100644 --- a/lib/pages/video/detail/note/note_list_page.dart +++ b/lib/pages/video/detail/note/note_list_page.dart @@ -111,6 +111,7 @@ class _NoteListPageState extends CommonSlidePageState { onPressed: () { _key.currentState?.showBottomSheet( (context) => WebviewPageNew( + uaType: 'android', oid: widget.oid, title: widget.title, url: diff --git a/lib/pages/webview/webview_page.dart b/lib/pages/webview/webview_page.dart index 1c92a826..4f549240 100644 --- a/lib/pages/webview/webview_page.dart +++ b/lib/pages/webview/webview_page.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:io'; import 'package:PiliPlus/http/init.dart'; -import 'package:PiliPlus/http/video.dart'; import 'package:PiliPlus/utils/accounts/account.dart'; import 'package:PiliPlus/utils/app_scheme.dart'; import 'package:PiliPlus/utils/cache_manage.dart'; @@ -193,20 +192,33 @@ class _WebviewPageNewState extends State { _webViewController?.evaluateJavascript(source: """ Array.from(document.querySelectorAll('.ql-editor > p')).map(p => p.textContent).join('\\n'); """).then((value) { - try { - String? summary = (value as String?); - if (summary?.isNotEmpty == true) { - VideoHttp.addNote( - oid: widget.oid!, - title: widget.title!, - summary: summary!, - ); - } - } catch (_) {} + // try { + // String? summary = (value as String?); + // if (summary?.isNotEmpty == true) { + // VideoHttp.addNote( + // oid: widget.oid!, + // title: widget.title!, + // summary: summary!, + // ); + // } + // } catch (_) {} Get.back(); }); }, ); + _webViewController?.addJavaScriptHandler( + handlerName: 'infoBarClicked', + callback: (args) async { + WebUri? uri = await _webViewController?.getUrl(); + if (uri != null) { + String? oid = + RegExp(r'oid=(\d+)').firstMatch(uri.toString())?.group(1); + if (oid != null) { + PiliScheme.videoPush(int.parse(oid), null); + } + } + }, + ); }, onProgressChanged: (controller, progress) { _progressStream.add(progress / 100); @@ -223,6 +235,11 @@ class _WebviewPageNewState extends State { document.querySelector('.finish-btn').addEventListener('click', function() { window.flutter_inappwebview.callHandler('finishButtonClicked'); }); +"""); + _webViewController?.evaluateJavascript(source: """ + document.querySelector('.info-bar').addEventListener('click', function() { + window.flutter_inappwebview.callHandler('infoBarClicked'); + }); """); } else if (url.toString().startsWith('https://live.bilibili.com')) { _webViewController?.evaluateJavascript(