mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-16 15:16:15 +08:00
opt history account
Closes #948 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:PiliPlus/models_new/space_setting/data.dart';
|
||||
import 'package:PiliPlus/models_new/sub/sub/data.dart';
|
||||
import 'package:PiliPlus/models_new/video/video_tag/data.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/wbi_sign.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -80,6 +81,7 @@ class UserHttp {
|
||||
required String type,
|
||||
int? max,
|
||||
int? viewAt,
|
||||
Account? account,
|
||||
}) async {
|
||||
var res = await Request().get(
|
||||
Api.historyList,
|
||||
@@ -89,6 +91,7 @@ class UserHttp {
|
||||
'max': max ?? 0,
|
||||
'view_at': viewAt ?? 0,
|
||||
},
|
||||
options: Options(extra: {'account': account ?? Accounts.history}),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return Success(HistoryData.fromJson(res.data['data']));
|
||||
@@ -98,22 +101,27 @@ class UserHttp {
|
||||
}
|
||||
|
||||
// 暂停观看历史
|
||||
static Future pauseHistory(bool switchStatus) async {
|
||||
static Future pauseHistory(bool switchStatus, {Account? account}) async {
|
||||
// 暂停switchStatus传true 否则false
|
||||
account ??= Accounts.history;
|
||||
var res = await Request().post(
|
||||
Api.pauseHistory,
|
||||
queryParameters: {
|
||||
'switch': switchStatus,
|
||||
'jsonp': 'jsonp',
|
||||
'csrf': Accounts.heartbeat.csrf,
|
||||
'csrf': account.csrf,
|
||||
},
|
||||
options: Options(extra: {'account': account}),
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
// 观看历史暂停状态
|
||||
static Future historyStatus() async {
|
||||
var res = await Request().get(Api.historyStatus);
|
||||
static Future historyStatus({Account? account}) async {
|
||||
var res = await Request().get(
|
||||
Api.historyStatus,
|
||||
options: Options(extra: {'account': account ?? Accounts.history}),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return {'status': true, 'data': res.data['data']};
|
||||
} else {
|
||||
@@ -122,13 +130,15 @@ class UserHttp {
|
||||
}
|
||||
|
||||
// 清空历史记录
|
||||
static Future clearHistory() async {
|
||||
static Future clearHistory({Account? account}) async {
|
||||
account ??= Accounts.history;
|
||||
var res = await Request().post(
|
||||
Api.clearHistory,
|
||||
queryParameters: {
|
||||
'jsonp': 'jsonp',
|
||||
'csrf': Accounts.heartbeat.csrf,
|
||||
'csrf': account.csrf,
|
||||
},
|
||||
options: Options(extra: {'account': account}),
|
||||
);
|
||||
return res;
|
||||
}
|
||||
@@ -204,15 +214,17 @@ class UserHttp {
|
||||
}
|
||||
|
||||
// 删除历史记录
|
||||
static Future delHistory(String kid) async {
|
||||
static Future delHistory(String kid, {Account? account}) async {
|
||||
account ??= Accounts.history;
|
||||
var res = await Request().post(
|
||||
Api.delHistory,
|
||||
data: {
|
||||
'kid': kid,
|
||||
'jsonp': 'jsonp',
|
||||
'csrf': Accounts.heartbeat.csrf,
|
||||
'csrf': account.csrf,
|
||||
},
|
||||
options: Options(
|
||||
extra: {'account': account},
|
||||
contentType: Headers.formUrlEncodedContentType,
|
||||
),
|
||||
);
|
||||
@@ -241,6 +253,7 @@ class UserHttp {
|
||||
static Future<LoadingState<HistoryData>> searchHistory({
|
||||
required int pn,
|
||||
required String keyword,
|
||||
Account? account,
|
||||
}) async {
|
||||
var res = await Request().get(
|
||||
Api.searchHistory,
|
||||
@@ -249,6 +262,7 @@ class UserHttp {
|
||||
'keyword': keyword,
|
||||
'business': 'all',
|
||||
},
|
||||
options: Options(extra: {'account': account ?? Accounts.history}),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return Success(HistoryData.fromJson(res.data['data']));
|
||||
|
||||
@@ -23,6 +23,7 @@ import 'package:PiliPlus/models_new/video/video_note_list/data.dart';
|
||||
import 'package:PiliPlus/models_new/video/video_play_info/data.dart';
|
||||
import 'package:PiliPlus/models_new/video/video_relation/data.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
@@ -674,15 +675,18 @@ class VideoHttp {
|
||||
required int desc,
|
||||
required dynamic oid,
|
||||
required dynamic upperMid,
|
||||
Account? account,
|
||||
}) async {
|
||||
account ??= Accounts.history;
|
||||
await Request().post(
|
||||
Api.mediaListHistory,
|
||||
queryParameters: {
|
||||
'desc': desc,
|
||||
'oid': oid,
|
||||
'upper_mid': upperMid,
|
||||
'csrf': Accounts.heartbeat.csrf,
|
||||
'csrf': account.csrf,
|
||||
},
|
||||
options: Options(extra: {'account': account}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,6 +12,8 @@ class HistoryBaseController extends GetxController {
|
||||
RxBool enableMultiSelect = false.obs;
|
||||
RxInt checkedCount = 0.obs;
|
||||
|
||||
final account = Accounts.history;
|
||||
|
||||
// 清空观看历史
|
||||
void onClearHistory(BuildContext context, VoidCallback onSuccess) {
|
||||
showDialog(
|
||||
@@ -31,7 +34,7 @@ class HistoryBaseController extends GetxController {
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
var res = await UserHttp.clearHistory();
|
||||
var res = await UserHttp.clearHistory(account: account);
|
||||
SmartDialog.dismiss();
|
||||
if (res.data['code'] == 0) {
|
||||
SmartDialog.showToast('清空观看历史');
|
||||
@@ -66,7 +69,10 @@ class HistoryBaseController extends GetxController {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
SmartDialog.showLoading(msg: '请求中');
|
||||
var res = await UserHttp.pauseHistory(pauseStatus);
|
||||
var res = await UserHttp.pauseHistory(
|
||||
pauseStatus,
|
||||
account: account,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (res.data['code'] == 0) {
|
||||
SmartDialog.showToast(pauseStatus ? '暂停观看历史' : '恢复观看历史');
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:PiliPlus/models_new/history/list.dart';
|
||||
import 'package:PiliPlus/models_new/history/tab.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select/multi_select_controller.dart';
|
||||
import 'package:PiliPlus/pages/history/base_controller.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
@@ -20,6 +21,8 @@ class HistoryController
|
||||
|
||||
late final baseCtr = Get.put(HistoryBaseController());
|
||||
|
||||
Account get account => baseCtr.account;
|
||||
|
||||
final String? type;
|
||||
TabController? tabController;
|
||||
late RxList<HistoryTab> tabs = <HistoryTab>[].obs;
|
||||
@@ -74,7 +77,7 @@ class HistoryController
|
||||
|
||||
// 观看历史暂停状态
|
||||
Future<void> historyStatus() async {
|
||||
var res = await UserHttp.historyStatus();
|
||||
var res = await UserHttp.historyStatus(account: account);
|
||||
if (res['status']) {
|
||||
baseCtr.pauseStatus.value = res['data'];
|
||||
GStorage.localCache.put(LocalCacheKey.historyPause, res['data']);
|
||||
@@ -90,15 +93,13 @@ class HistoryController
|
||||
|
||||
// 删除已看历史记录
|
||||
void onDelViewedHistory() {
|
||||
if (loadingState.value.isSuccess) {
|
||||
final viewedList = loadingState.value.data!
|
||||
.where((e) => e.progress == -1)
|
||||
.toSet();
|
||||
if (viewedList.isNotEmpty) {
|
||||
_onDelete(viewedList);
|
||||
} else {
|
||||
SmartDialog.showToast('无已看记录');
|
||||
}
|
||||
final viewedList = loadingState.value.dataOrNull
|
||||
?.where((e) => e.progress == -1)
|
||||
.toSet();
|
||||
if (viewedList != null && viewedList.isNotEmpty) {
|
||||
_onDelete(viewedList);
|
||||
} else {
|
||||
SmartDialog.showToast('无已看记录');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +109,7 @@ class HistoryController
|
||||
removeList
|
||||
.map((item) => '${item.history.business}_${item.kid}')
|
||||
.join(','),
|
||||
account: account,
|
||||
);
|
||||
if (response['status']) {
|
||||
afterDelete(removeList);
|
||||
@@ -128,8 +130,12 @@ class HistoryController
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<HistoryData>> customGetData() =>
|
||||
UserHttp.historyList(type: type ?? 'all', max: max, viewAt: viewAt);
|
||||
Future<LoadingState<HistoryData>> customGetData() => UserHttp.historyList(
|
||||
type: type ?? 'all',
|
||||
max: max,
|
||||
viewAt: viewAt,
|
||||
account: account,
|
||||
);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:PiliPlus/models_new/history/data.dart';
|
||||
import 'package:PiliPlus/models_new/history/list.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select/base.dart';
|
||||
import 'package:PiliPlus/pages/common/search/common_search_controller.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -15,6 +16,7 @@ class HistorySearchController
|
||||
Future<LoadingState<HistoryData>> customGetData() => UserHttp.searchHistory(
|
||||
pn: page,
|
||||
keyword: editController.value.text,
|
||||
account: account,
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -22,8 +24,13 @@ class HistorySearchController
|
||||
return response.list;
|
||||
}
|
||||
|
||||
final account = Accounts.history;
|
||||
|
||||
Future<void> onDelHistory(int index, kid, String business) async {
|
||||
var res = await UserHttp.delHistory('${business}_$kid');
|
||||
var res = await UserHttp.delHistory(
|
||||
'${business}_$kid',
|
||||
account: account,
|
||||
);
|
||||
if (res['status']) {
|
||||
loadingState
|
||||
..value.data!.removeAt(index)
|
||||
@@ -45,6 +52,7 @@ class HistorySearchController
|
||||
removeList
|
||||
.map((item) => '${item.history.business!}_${item.kid!}')
|
||||
.join(','),
|
||||
account: account,
|
||||
);
|
||||
if (response['status']) {
|
||||
afterDelete(removeList);
|
||||
|
||||
@@ -16,6 +16,13 @@ class Accounts {
|
||||
static final Map<AccountType, Account> accountMode = {};
|
||||
static Account get main => accountMode[AccountType.main]!;
|
||||
static Account get heartbeat => accountMode[AccountType.heartbeat]!;
|
||||
static Account get history {
|
||||
final heartbeat = Accounts.heartbeat;
|
||||
if (heartbeat is AnonymousAccount) {
|
||||
return Accounts.main;
|
||||
}
|
||||
return heartbeat;
|
||||
}
|
||||
// static set main(Account account) => set(AccountType.main, account);
|
||||
|
||||
static Future<void> init() async {
|
||||
|
||||
@@ -29,13 +29,13 @@ class AccountManager extends Interceptor {
|
||||
Api.heartBeat,
|
||||
Api.historyReport,
|
||||
Api.roomEntryAction,
|
||||
Api.historyList,
|
||||
Api.pauseHistory,
|
||||
Api.clearHistory,
|
||||
Api.delHistory,
|
||||
Api.searchHistory,
|
||||
Api.historyStatus,
|
||||
Api.mediaListHistory,
|
||||
// Api.historyList,
|
||||
// Api.pauseHistory,
|
||||
// Api.clearHistory,
|
||||
// Api.delHistory,
|
||||
// Api.searchHistory,
|
||||
// Api.historyStatus,
|
||||
// Api.mediaListHistory,
|
||||
// progress
|
||||
Api.pgcInfo,
|
||||
Api.pugvInfo,
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:PiliPlus/utils/storage_key.dart';
|
||||
|
||||
class Data {
|
||||
static Future<void> init() async {
|
||||
if (!Accounts.main.isLogin) {
|
||||
if (!Accounts.history.isLogin) {
|
||||
return;
|
||||
}
|
||||
var res = await UserHttp.historyStatus();
|
||||
|
||||
Reference in New Issue
Block a user