mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-23 12:10:33 +08:00
feat: account manager (#468)
* feat: account manager * remove dep * some fixes * migrate accounts * reimplement clearCookie
This commit is contained in:
committed by
GitHub
parent
94fa0652ac
commit
b15fdfa2ff
@@ -16,9 +16,7 @@ class RecommendSetting extends StatelessWidget {
|
||||
ListTile(
|
||||
dense: true,
|
||||
subtitle: Text(
|
||||
'¹ 若默认web端推荐不太符合预期,可尝试切换至app端。\n'
|
||||
'¹ 选择“游客模式(notLogin)”,将以空的key请求app推荐接口,但播放页仍会携带用户信息,保证账号能正常记录进度、点赞投币等。\n\n'
|
||||
'² 由于接口未提供关注信息,无法豁免相关视频中的已关注Up。\n\n'
|
||||
'¹ 由于接口未提供关注信息,无法豁免相关视频中的已关注Up。\n\n'
|
||||
'* 其它(如热门视频、手动搜索、链接跳转等)均不受过滤器影响。\n'
|
||||
'* 设定较严苛的条件可导致推荐项数锐减或多次请求,请酌情选择。\n'
|
||||
'* 后续可能会增加更多过滤条件,敬请期待。',
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:PiliPlus/models/common/sponsor_block/skip_type.dart';
|
||||
import 'package:PiliPlus/pages/setting/slide_color_picker.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -66,7 +65,6 @@ class _SponsorBlockPageState extends State<SponsorBlockPage> {
|
||||
Request()
|
||||
.get(
|
||||
'$_blockServer/api/status/uptime',
|
||||
options: Options(extra: {'clearCookie': true}),
|
||||
)
|
||||
.then((res) {
|
||||
setState(() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/build_config.dart';
|
||||
import 'package:PiliPlus/http/login.dart';
|
||||
import 'package:PiliPlus/pages/about/index.dart';
|
||||
import 'package:PiliPlus/pages/login/controller.dart';
|
||||
import 'package:PiliPlus/pages/setting/extra_setting.dart';
|
||||
import 'package:PiliPlus/pages/setting/play_setting.dart';
|
||||
import 'package:PiliPlus/pages/setting/privacy_setting.dart';
|
||||
@@ -9,13 +10,10 @@ import 'package:PiliPlus/pages/setting/video_setting.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/login.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../http/init.dart';
|
||||
|
||||
class _SettingsModel {
|
||||
final String name;
|
||||
final String title;
|
||||
@@ -39,7 +37,7 @@ class SettingPage extends StatefulWidget {
|
||||
|
||||
class _SettingPageState extends State<SettingPage> {
|
||||
late String _type = 'privacySetting';
|
||||
final RxBool _isLogin = GStorage.isLogin.obs;
|
||||
final RxBool _isLogin = Accounts.main.isLogin.obs;
|
||||
TextStyle get _titleStyle => Theme.of(context).textTheme.titleMedium!;
|
||||
TextStyle get _subTitleStyle => Theme.of(context)
|
||||
.textTheme
|
||||
@@ -170,6 +168,12 @@ class _SettingPageState extends State<SettingPage> {
|
||||
: Text(item.subtitle!, style: _subTitleStyle),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () => LoginPageController.switchAccountDialog(context),
|
||||
leading: const Icon(Icons.switch_account_outlined),
|
||||
title: const Text('设置账号模式'),
|
||||
),
|
||||
// TODO: 多账号登出
|
||||
_buildLoginItem,
|
||||
ListTile(
|
||||
tileColor: _getTileColor(_items.last.name),
|
||||
@@ -204,41 +208,36 @@ class _SettingPageState extends State<SettingPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (BuildConfig.isDebug)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
_isLogin.value = false;
|
||||
LoginUtils.onLogout();
|
||||
},
|
||||
child: Text(
|
||||
'仅登出',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
_isLogin.value = false;
|
||||
LoginUtils.onLogoutMain();
|
||||
final account = Accounts.main;
|
||||
Accounts.accountMode
|
||||
.removeWhere((_, a) => a == account);
|
||||
account.logout().then((_) => Accounts.refresh());
|
||||
},
|
||||
child: Text(
|
||||
'仅登出',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
SmartDialog.showLoading();
|
||||
dynamic res = await Request().post(
|
||||
'https://passport.bilibili.com/login/exit/v2',
|
||||
data: {
|
||||
'biliCSRF': await Request.getCsrf(),
|
||||
},
|
||||
options: Options(
|
||||
contentType:
|
||||
Headers.formUrlEncodedContentType,
|
||||
),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
await LoginUtils.onLogout();
|
||||
final res = await LoginHttp.logout(Accounts.main);
|
||||
if (res['status']) {
|
||||
await Accounts.main.logout();
|
||||
await LoginUtils.onLogoutMain();
|
||||
_isLogin.value = false;
|
||||
SmartDialog.dismiss();
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.dismiss();
|
||||
SmartDialog.showToast('${res.data['message']}');
|
||||
SmartDialog.showToast(res['msg'].toString());
|
||||
}
|
||||
},
|
||||
child: const Text('确认'),
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart'
|
||||
show kDragContainerExtentPercentage, displacement;
|
||||
import 'package:PiliPlus/http/interceptor.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
@@ -11,7 +10,6 @@ import 'package:PiliPlus/models/common/audio_normalization.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/models/common/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/common/nav_bar_config.dart';
|
||||
import 'package:PiliPlus/models/common/rcmd_type.dart';
|
||||
import 'package:PiliPlus/models/common/reply_sort_type.dart';
|
||||
import 'package:PiliPlus/models/common/super_resolution_type.dart';
|
||||
import 'package:PiliPlus/models/common/theme_type.dart';
|
||||
@@ -35,6 +33,7 @@ import 'package:PiliPlus/pages/setting/widgets/switch_item.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
@@ -1229,35 +1228,19 @@ List<SettingsModel> get videoSettings => [
|
||||
|
||||
List<SettingsModel> get recommendSettings => [
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.normal,
|
||||
title: '首页推荐类型',
|
||||
leading: const Icon(Icons.model_training_outlined),
|
||||
getSubtitle: () => '当前使用「${GStorage.defaultRcmdType}端」推荐¹',
|
||||
onTap: (setState) async {
|
||||
String? result = await showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) {
|
||||
return SelectDialog<String>(
|
||||
title: '推荐类型',
|
||||
value: GStorage.defaultRcmdType,
|
||||
values: RcmdType.values.map((e) {
|
||||
return {'title': e.labels, 'value': e.values};
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
if (result == 'app') {
|
||||
if (GStorage.isLogin.not) {
|
||||
SmartDialog.showToast('尚未登录,无法收到个性化推荐');
|
||||
}
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '首页使用app端推荐',
|
||||
subtitle: '若web端推荐不太符合预期,可尝试切换至app端推荐',
|
||||
leading: const Icon(Icons.model_training_outlined),
|
||||
setKey: SettingBoxKey.appRcmd,
|
||||
defaultVal: true,
|
||||
onChanged: (value) {
|
||||
try {
|
||||
Get.find<RcmdController>().appRcmd = value;
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
}
|
||||
await GStorage.setting.put(SettingBoxKey.defaultRcmdType, result);
|
||||
SmartDialog.showToast('下次启动时生效');
|
||||
setState();
|
||||
}
|
||||
},
|
||||
),
|
||||
}),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '推荐动态',
|
||||
@@ -1430,7 +1413,7 @@ List<SettingsModel> get recommendSettings => [
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '过滤器也应用于相关视频',
|
||||
subtitle: '视频详情页的相关视频也进行过滤²',
|
||||
subtitle: '视频详情页的相关视频也进行过滤¹',
|
||||
leading: const Icon(Icons.explore_outlined),
|
||||
setKey: SettingBoxKey.applyFilterToRelatedVideos,
|
||||
defaultVal: true,
|
||||
@@ -1442,7 +1425,7 @@ List<SettingsModel> get privacySettings => [
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.normal,
|
||||
onTap: (setState) {
|
||||
if (GStorage.isLogin.not) {
|
||||
if (Accounts.main.isLogin.not) {
|
||||
SmartDialog.showToast('登录后查看');
|
||||
return;
|
||||
}
|
||||
@@ -1472,7 +1455,8 @@ List<SettingsModel> get privacySettings => [
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('查看详情'),
|
||||
content: Text(ApiInterceptor.anonymityList.join('\n')),
|
||||
content: Text(AccountManager.apiTypeSet[AccountType.heartbeat]!
|
||||
.join('\n')),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
@@ -1501,12 +1485,9 @@ List<SettingsModel> get extraSettings => [
|
||||
onTap: () => Get.toNamed('/sponsorBlock'),
|
||||
leading: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
const Icon(Icons.shield_outlined),
|
||||
Icon(
|
||||
Icons.play_arrow_rounded,
|
||||
size: 15,
|
||||
),
|
||||
children: const [
|
||||
Icon(Icons.shield_outlined),
|
||||
Icon(Icons.play_arrow_rounded, size: 15),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -2056,9 +2037,9 @@ List<SettingsModel> get extraSettings => [
|
||||
subtitle: '发送评论后检查评论是否可见',
|
||||
leading: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
const Icon(Icons.shield_outlined),
|
||||
const Icon(Icons.reply, size: 14),
|
||||
children: const [
|
||||
Icon(Icons.shield_outlined),
|
||||
Icon(Icons.reply, size: 14),
|
||||
],
|
||||
),
|
||||
setKey: SettingBoxKey.enableCommAntifraud,
|
||||
@@ -2081,12 +2062,9 @@ List<SettingsModel> get extraSettings => [
|
||||
subtitle: '发布/转发动态后检查动态是否可见',
|
||||
leading: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
const Icon(Icons.shield_outlined),
|
||||
Icon(
|
||||
Icons.motion_photos_on,
|
||||
size: 12,
|
||||
),
|
||||
children: const [
|
||||
Icon(Icons.shield_outlined),
|
||||
Icon(Icons.motion_photos_on, size: 12),
|
||||
],
|
||||
),
|
||||
setKey: SettingBoxKey.enableCreateDynAntifraud,
|
||||
@@ -2097,7 +2075,7 @@ List<SettingsModel> get extraSettings => [
|
||||
title: '屏蔽带货动态',
|
||||
leading: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
children: const [
|
||||
Icon(Icons.shopping_bag_outlined, size: 14),
|
||||
Icon(Icons.not_interested),
|
||||
],
|
||||
@@ -2113,7 +2091,7 @@ List<SettingsModel> get extraSettings => [
|
||||
title: '屏蔽带货评论',
|
||||
leading: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
children: const [
|
||||
Icon(Icons.shopping_bag_outlined, size: 14),
|
||||
Icon(Icons.not_interested),
|
||||
],
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/video/play/CDN.dart';
|
||||
import 'package:PiliPlus/models/video/play/url.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/video_utils.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -46,23 +45,12 @@ class _SelectDialogState<T> extends State<SelectDialog<T>> {
|
||||
if (result['status']) {
|
||||
VideoItem videoItem = result['data'].dash.video.first;
|
||||
|
||||
late final isLogin = GStorage.isLogin;
|
||||
late final dynamic mid =
|
||||
GStorage.userInfo.get('userInfoCache')?.mid;
|
||||
|
||||
for (CDNService item in CDNService.values) {
|
||||
if (mounted.not) {
|
||||
break;
|
||||
}
|
||||
String videoUrl = VideoUtils.getCdnUrl(videoItem, item.code);
|
||||
Dio dio = Dio()
|
||||
..options.headers['referer'] = 'https://www.bilibili.com/';
|
||||
if (isLogin) {
|
||||
dio.interceptors.add(Request.cookieManager);
|
||||
dio.options.headers['x-bili-mid'] = mid;
|
||||
dio.options.headers['x-bili-aurora-eid'] =
|
||||
IdUtils.genAuroraEid(mid);
|
||||
}
|
||||
Dio dio = Dio()..options.headers['referer'] = HttpString.baseUrl;
|
||||
int maxSize = 8 * 1024 * 1024;
|
||||
int downloaded = 0;
|
||||
int start = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
Reference in New Issue
Block a user