mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-17 23:56:13 +08:00
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/retry_interceptor.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
@@ -11,6 +12,7 @@ import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:brotli/brotli.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -62,36 +64,35 @@ class Request {
|
||||
}
|
||||
}
|
||||
|
||||
// static Future<void> buvidActive(Account account) async {
|
||||
// // 这样线程不安全, 但仍按预期进行
|
||||
// if (account.activited) return;
|
||||
// account.activited = true;
|
||||
// try {
|
||||
// final html = await Request().get(Api.dynamicSpmPrefix,
|
||||
// options: Options(extra: {'account': account}));
|
||||
// final String spmPrefix = _spmPrefixExp.firstMatch(html.data)!.group(1)!;
|
||||
// final String randPngEnd = base64.encode(
|
||||
// List<int>.generate(32, (_) => _rand.nextInt(256)) +
|
||||
// List<int>.filled(4, 0) +
|
||||
// [73, 69, 78, 68] +
|
||||
// List<int>.generate(4, (_) => _rand.nextInt(256)));
|
||||
static Future<void> buvidActive(Account account) async {
|
||||
// 这样线程不安全, 但仍按预期进行
|
||||
if (account.activited) return;
|
||||
account.activited = true;
|
||||
try {
|
||||
// final html = await Request().get(Api.dynamicSpmPrefix,
|
||||
// options: Options(extra: {'account': account}));
|
||||
// final String spmPrefix = _spmPrefixExp.firstMatch(html.data)!.group(1)!;
|
||||
final String randPngEnd = base64.encode(
|
||||
List<int>.generate(32, (_) => Utils.random.nextInt(256)) +
|
||||
List<int>.filled(4, 0) +
|
||||
[73, 69, 78, 68] +
|
||||
List<int>.generate(4, (_) => Utils.random.nextInt(256)));
|
||||
|
||||
// String jsonData = json.encode({
|
||||
// '3064': 1,
|
||||
// '39c8': '$spmPrefix.fp.risk',
|
||||
// '3c43': {
|
||||
// 'adca': 'Linux',
|
||||
// 'bfe9': randPngEnd.substring(randPngEnd.length - 50),
|
||||
// },
|
||||
// });
|
||||
String jsonData = json.encode({
|
||||
'3064': 1,
|
||||
'39c8':
|
||||
'${account is AnonymousAccount ? '333.1365' : '333.788'}.fp.risk',
|
||||
'3c43': {
|
||||
'adca': 'Linux',
|
||||
'bfe9': randPngEnd.substring(randPngEnd.length - 50),
|
||||
},
|
||||
});
|
||||
|
||||
// await Request().post(Api.activateBuvidApi,
|
||||
// data: {'payload': jsonData},
|
||||
// options: Options(contentType: Headers.jsonContentType));
|
||||
// } catch (e) {
|
||||
// log("setCookie, $e");
|
||||
// }
|
||||
// }
|
||||
await Request().post(Api.activateBuvidApi,
|
||||
data: {'payload': jsonData},
|
||||
options: Options(contentType: Headers.jsonContentType));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/*
|
||||
* config it and create
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/models/common/account_type.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
@@ -55,7 +56,7 @@ class Accounts {
|
||||
}
|
||||
}
|
||||
|
||||
static void refresh() {
|
||||
static Future<void> refresh() async {
|
||||
for (var a in account.values) {
|
||||
for (var t in a.type) {
|
||||
accountMode[t] = a;
|
||||
@@ -64,9 +65,9 @@ class Accounts {
|
||||
for (var type in AccountType.values) {
|
||||
accountMode[type] ??= AnonymousAccount();
|
||||
}
|
||||
// await Future.wait((accountMode.values.toSet()
|
||||
// ..retainWhere((i) => !i.activited))
|
||||
// .map((i) => Request.buvidActive(i)));
|
||||
await Future.wait((accountMode.values.toSet()
|
||||
..retainWhere((i) => !i.activited))
|
||||
.map((i) => Request.buvidActive(i)));
|
||||
}
|
||||
|
||||
static Future<void> clear() async {
|
||||
@@ -75,7 +76,7 @@ class Accounts {
|
||||
accountMode[i] = AnonymousAccount();
|
||||
}
|
||||
await AnonymousAccount().delete();
|
||||
// Request.buvidActive(AnonymousAccount());
|
||||
Request.buvidActive(AnonymousAccount());
|
||||
}
|
||||
|
||||
static void close() {
|
||||
@@ -98,7 +99,7 @@ class Accounts {
|
||||
await (accountMode[key]?..type.remove(key))?.onChange();
|
||||
accountMode[key] = account..type.add(key);
|
||||
await account.onChange();
|
||||
// if (!account.activited) await Request.buvidActive(account);
|
||||
if (!account.activited) await Request.buvidActive(account);
|
||||
switch (key) {
|
||||
case AccountType.main:
|
||||
await (account.isLogin
|
||||
|
||||
@@ -15,7 +15,7 @@ abstract class Account {
|
||||
late String csrf;
|
||||
final Map<String, String> headers = const {};
|
||||
|
||||
// bool activited = false;
|
||||
bool activited = false;
|
||||
|
||||
Future<void> delete();
|
||||
Future<void> onChange();
|
||||
@@ -40,6 +40,9 @@ class LoginAccount implements Account {
|
||||
@HiveField(3)
|
||||
late final Set<AccountType> type;
|
||||
|
||||
@override
|
||||
bool activited = false;
|
||||
|
||||
@override
|
||||
late final int mid = int.parse(_midStr);
|
||||
|
||||
@@ -113,6 +116,9 @@ class AnonymousAccount implements Account {
|
||||
@override
|
||||
final Map<String, String> headers = const {};
|
||||
|
||||
@override
|
||||
bool activited = false;
|
||||
|
||||
@override
|
||||
Future<void> delete() async {
|
||||
await cookieJar.deleteAll();
|
||||
|
||||
Reference in New Issue
Block a user