mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-13 06:11:43 +08:00
feat: load config from text (#1772)
* feat: load config from text * opt: login utils * update Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
b4daf5fbd8
commit
244ef22f54
@@ -106,9 +106,9 @@ abstract class Accounts {
|
||||
}
|
||||
|
||||
static Future<void> set(AccountType key, Account account) async {
|
||||
await (accountMode[key.index]..type.remove(key)).onChange();
|
||||
final oldAccount = accountMode[key.index]..type.remove(key);
|
||||
accountMode[key.index] = account..type.add(key);
|
||||
await account.onChange();
|
||||
await Future.wait([account.onChange(), oldAccount.onChange()]);
|
||||
if (!account.activated) await Request.buvidActive(account);
|
||||
switch (key) {
|
||||
case AccountType.main:
|
||||
|
||||
@@ -2,19 +2,9 @@ import 'dart:async' show FutureOr;
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:PiliPlus/grpc/grpc_req.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/common/home_tab_type.dart';
|
||||
import 'package:PiliPlus/models/user/info.dart';
|
||||
import 'package:PiliPlus/models/user/stat.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/controller.dart';
|
||||
import 'package:PiliPlus/pages/live/controller.dart';
|
||||
import 'package:PiliPlus/pages/main/controller.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/pages/pgc/controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
@@ -22,11 +12,13 @@ import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:crypto/crypto.dart' show Digest;
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
abstract class LoginUtils {
|
||||
abstract final class LoginUtils {
|
||||
static FutureOr setWebCookie([Account? account]) {
|
||||
if (Platform.isLinux) {
|
||||
return null;
|
||||
@@ -62,48 +54,19 @@ abstract class LoginUtils {
|
||||
if (result.isSuccess) {
|
||||
final UserInfoData data = result.data;
|
||||
if (data.isLogin == true) {
|
||||
Get.find<AccountService>()
|
||||
..mid = data.mid!
|
||||
..name.value = data.uname!
|
||||
..face.value = data.face!
|
||||
..isLogin.value = true;
|
||||
final accountService = Get.find<AccountService>()
|
||||
..face.value = data.face!;
|
||||
|
||||
if (accountService.isLogin.value) {
|
||||
accountService.isLogin.refresh();
|
||||
} else {
|
||||
accountService.isLogin.value = true;
|
||||
}
|
||||
|
||||
SmartDialog.showToast('main登录成功');
|
||||
if (data != Pref.userInfoCache) {
|
||||
await GStorage.userInfo.put('userInfoCache', data);
|
||||
}
|
||||
|
||||
try {
|
||||
Get.find<MineController>().onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<DynamicsController>().onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
for (var item in DynamicsTabType.values) {
|
||||
try {
|
||||
Get.find<DynamicsTabController>(tag: item.name).onRefresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
try {
|
||||
Get.find<LiveController>().onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<PgcController>(tag: HomeTabType.bangumi.name)
|
||||
..followPage = 1
|
||||
..followEnd = false
|
||||
..queryPgcFollow();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<PgcController>(tag: HomeTabType.cinema.name)
|
||||
..followPage = 1
|
||||
..followEnd = false
|
||||
..queryPgcFollow();
|
||||
} catch (_) {}
|
||||
}
|
||||
} else {
|
||||
// 获取用户信息失败
|
||||
@@ -115,65 +78,26 @@ abstract class LoginUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> onLogoutMain() async {
|
||||
static Future<void> onLogoutMain() {
|
||||
Get.find<AccountService>()
|
||||
..mid = 0
|
||||
..name.value = ''
|
||||
..face.value = ''
|
||||
..isLogin.value = false;
|
||||
|
||||
GrpcReq.updateHeaders(null);
|
||||
|
||||
await Future.wait([
|
||||
return Future.wait([
|
||||
if (!Platform.isLinux)
|
||||
web.CookieManager.instance(
|
||||
webViewEnvironment: webViewEnvironment,
|
||||
).deleteAllCookies(),
|
||||
GStorage.userInfo.delete('userInfoCache'),
|
||||
]);
|
||||
|
||||
try {
|
||||
Get.find<MainController>().setDynCount();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<MineController>()
|
||||
..userInfo.value = UserInfoData()
|
||||
..userStat.value = UserStat()
|
||||
..loadingState.value = LoadingState.loading();
|
||||
// MineController.anonymity.value = false;
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<DynamicsController>().onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<LiveController>().onRefresh();
|
||||
} catch (_) {}
|
||||
|
||||
for (var item in DynamicsTabType.values) {
|
||||
try {
|
||||
Get.find<DynamicsTabController>(tag: item.name).onRefresh();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
try {
|
||||
Get.find<PgcController>(tag: HomeTabType.bangumi.name).followState.value =
|
||||
LoadingState.loading();
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
Get.find<PgcController>(tag: HomeTabType.cinema.name).followState.value =
|
||||
LoadingState.loading();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static String generateBuvid() {
|
||||
var md5Str = Iterable.generate(
|
||||
32,
|
||||
(_) => Utils.random.nextInt(16).toRadixString(16),
|
||||
).join().toUpperCase();
|
||||
var md5Str = Digest(
|
||||
List.generate(16, (_) => Utils.random.nextInt(256)),
|
||||
).toString();
|
||||
return 'XY${md5Str[2]}${md5Str[12]}${md5Str[22]}$md5Str';
|
||||
}
|
||||
|
||||
@@ -190,31 +114,26 @@ abstract class LoginUtils {
|
||||
|
||||
static String genDeviceId() {
|
||||
// https://github.com/bilive/bilive_client/blob/2873de0532c54832f5464a4c57325ad9af8b8698/bilive/lib/app_client.ts#L62
|
||||
final String yyyyMMddHHmmss = DateTime.now()
|
||||
.toIso8601String()
|
||||
.replaceAll(RegExp(r'[-:TZ]'), '')
|
||||
.substring(0, 14);
|
||||
final time = DateTime.now();
|
||||
|
||||
final String randomHex32 = List.generate(
|
||||
32,
|
||||
(index) => Utils.random.nextInt(16).toRadixString(16),
|
||||
).join();
|
||||
final String randomHex16 = List.generate(
|
||||
16,
|
||||
(index) => Utils.random.nextInt(16).toRadixString(16),
|
||||
).join();
|
||||
final List<int> bytes = [
|
||||
...Iterable.generate(16, (_) => Utils.random.nextInt(256)),
|
||||
_dec2bcd(time.year ~/ 100),
|
||||
_dec2bcd(time.year % 100),
|
||||
_dec2bcd(time.month),
|
||||
_dec2bcd(time.day),
|
||||
_dec2bcd(time.hour),
|
||||
_dec2bcd(time.minute),
|
||||
_dec2bcd(time.second),
|
||||
...Iterable.generate(8, (_) => Utils.random.nextInt(256)),
|
||||
];
|
||||
final check = (bytes.sum & 0xFF).toRadixString(16).padLeft(2, '0');
|
||||
|
||||
final String deviceID = randomHex32 + yyyyMMddHHmmss + randomHex16;
|
||||
return Digest(bytes).toString() + check;
|
||||
}
|
||||
|
||||
final List<int> bytes = RegExp(r'\w{2}')
|
||||
.allMatches(deviceID)
|
||||
.map((match) => int.parse(match.group(0)!, radix: 16))
|
||||
.toList();
|
||||
final int checksumValue = bytes.reduce((a, b) => a + b);
|
||||
final String check = checksumValue
|
||||
.toRadixString(16)
|
||||
.substring(checksumValue.toRadixString(16).length - 2);
|
||||
|
||||
return deviceID + check;
|
||||
static int _dec2bcd(int dec) {
|
||||
assert(0 <= dec && dec < 100);
|
||||
return ((dec ~/ 10) << 4) | (dec % 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ abstract class GStorage {
|
||||
importAllJsonSettings(jsonDecode(data));
|
||||
|
||||
static Future<bool> importAllJsonSettings(Map<String, dynamic> map) async {
|
||||
await setting.clear();
|
||||
await video.clear();
|
||||
await setting.putAll(map[setting.name]);
|
||||
await video.putAll(map[video.name]);
|
||||
await Future.wait([
|
||||
setting.clear().then((_) => setting.putAll(map[setting.name])),
|
||||
video.clear().then((_) => video.putAll(map[video.name])),
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user