mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: memberArchive challenge (#646)
This commit is contained in:
committed by
GitHub
parent
d3cbc95235
commit
5da86d85de
@@ -14,7 +14,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();
|
||||
@@ -51,9 +51,6 @@ class LoginAccount implements Account {
|
||||
late String csrf =
|
||||
cookieJar.domainCookies['bilibili.com']!['/']!['bili_jct']!.cookie.value;
|
||||
|
||||
@override
|
||||
bool activited = false;
|
||||
|
||||
@override
|
||||
Future<void> delete() => _box.delete(_midStr);
|
||||
|
||||
@@ -74,9 +71,8 @@ class LoginAccount implements Account {
|
||||
late final Box<LoginAccount> _box = Accounts.account;
|
||||
|
||||
LoginAccount(this.cookieJar, this.accessKey, this.refresh,
|
||||
[Set<AccountType>? type]) {
|
||||
this.type = type ?? {};
|
||||
}
|
||||
[Set<AccountType>? type])
|
||||
: this.type = type ?? {};
|
||||
|
||||
LoginAccount.fromJson(Map json) {
|
||||
cookieJar = BiliCookieJar.fromJson(json['cookies']);
|
||||
@@ -93,7 +89,7 @@ class LoginAccount implements Account {
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) || (other is Account && mid == other.mid);
|
||||
identical(this, other) || (other is LoginAccount && mid == other.mid);
|
||||
}
|
||||
|
||||
class AnonymousAccount implements Account {
|
||||
@@ -114,13 +110,10 @@ class AnonymousAccount implements Account {
|
||||
@override
|
||||
final Map<String, String> headers = const {};
|
||||
|
||||
@override
|
||||
bool activited = false;
|
||||
|
||||
@override
|
||||
Future<void> delete() async {
|
||||
await cookieJar.deleteAll();
|
||||
activited = false;
|
||||
cookieJar.setBuvid3();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -132,7 +125,7 @@ class AnonymousAccount implements Account {
|
||||
static final _instance = AnonymousAccount._();
|
||||
|
||||
AnonymousAccount._() {
|
||||
cookieJar = DefaultCookieJar(ignoreExpires: true);
|
||||
cookieJar = DefaultCookieJar(ignoreExpires: true)..setBuvid3();
|
||||
}
|
||||
|
||||
factory AnonymousAccount() => _instance;
|
||||
@@ -143,7 +136,7 @@ class AnonymousAccount implements Account {
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is Account && cookieJar == other.cookieJar);
|
||||
(other is AnonymousAccount && cookieJar == other.cookieJar);
|
||||
}
|
||||
|
||||
extension BiliCookie on Cookie {
|
||||
@@ -168,6 +161,12 @@ extension BiliCookieJar on DefaultCookieJar {
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
void setBuvid3() {
|
||||
domainCookies['bilibili.com'] ??= {'/': {}};
|
||||
domainCookies['bilibili.com']!['/']!['buvid3'] ??= SerializableCookie(
|
||||
Cookie('buvid3', Utils.genBuvid3())..setBiliDomain());
|
||||
}
|
||||
|
||||
static DefaultCookieJar fromJson(Map json) =>
|
||||
DefaultCookieJar(ignoreExpires: true)
|
||||
..domainCookies['bilibili.com'] = {
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart'
|
||||
show kDragContainerExtentPercentage, displacement;
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/index.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/models/common/sponsor_block/segment_type.dart';
|
||||
import 'package:PiliPlus/models/common/sponsor_block/skip_type.dart';
|
||||
@@ -903,9 +902,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 {
|
||||
@@ -914,7 +913,7 @@ class Accounts {
|
||||
accountMode[i] = AnonymousAccount();
|
||||
}
|
||||
await AnonymousAccount().delete();
|
||||
Request.buvidActive(AnonymousAccount());
|
||||
// Request.buvidActive(AnonymousAccount());
|
||||
}
|
||||
|
||||
static Future<void> close() async {
|
||||
@@ -936,7 +935,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
|
||||
|
||||
@@ -50,6 +50,7 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:html/dom.dart' as dom;
|
||||
import 'package:html/parser.dart' as html_parser;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:uuid/v4.dart';
|
||||
|
||||
import '../models/home/rcmd/result.dart';
|
||||
import '../models/model_rec_video_item.dart';
|
||||
@@ -1875,13 +1876,16 @@ class Utils {
|
||||
}
|
||||
|
||||
static List<int> generateRandomBytes(int minLength, int maxLength) {
|
||||
return List<int>.generate(random.nextInt(maxLength - minLength + 1),
|
||||
(_) => random.nextInt(0x60) + 0x20);
|
||||
return List<int>.generate(
|
||||
minLength + random.nextInt(maxLength - minLength + 1),
|
||||
(_) => 0x26 + random.nextInt(0x59), // dm_img_str不能有`%`
|
||||
);
|
||||
}
|
||||
|
||||
static String base64EncodeRandomString(int minLength, int maxLength) {
|
||||
List<int> randomBytes = generateRandomBytes(minLength, maxLength);
|
||||
return base64.encode(randomBytes);
|
||||
final randomBytes = generateRandomBytes(minLength, maxLength);
|
||||
final randomBase64 = base64.encode(randomBytes);
|
||||
return randomBase64.substring(0, randomBase64.length - 2);
|
||||
}
|
||||
|
||||
static String getFileName(String uri, {bool fileExt = true}) {
|
||||
@@ -1889,4 +1893,8 @@ class Utils {
|
||||
final i1 = fileExt ? uri.length : uri.lastIndexOf('.');
|
||||
return uri.substring(i0, i1);
|
||||
}
|
||||
|
||||
static String genBuvid3() {
|
||||
return '${const UuidV4().generate().toUpperCase()}${random.nextInt(100000).toString().padLeft(5, "0")}infoc';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user