fix: update grpc headers

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-05 00:58:37 +08:00
parent cfc66e4364
commit ef671f6503
2 changed files with 24 additions and 2 deletions

View File

@@ -51,8 +51,8 @@ class GrpcUrl {
}
class GrpcRepo {
static final String? _accessKey = Accounts.main.accessKey;
static const _build = 1462100;
static String? _accessKey = Accounts.main.accessKey;
static const _build = 2001100;
static const _biliChannel = 'bili';
static const _mobiApp = 'android_hd';
static const _phone = 'phone';
@@ -61,6 +61,24 @@ class GrpcRepo {
static final _traceId = Utils.genTraceId();
static final _sessionId = Utils.generateRandomString(8);
static void updateHeaders(String? accessKey) {
_accessKey = accessKey;
if (_accessKey != null) {
headers['authorization'] = 'identify_v1 $_accessKey';
} else {
headers.remove('authorization');
}
headers['x-bili-metadata-bin'] = base64Encode(Metadata(
accessKey: _accessKey ?? '',
mobiApp: _mobiApp,
device: _phone,
build: _build,
channel: _biliChannel,
buvid: _buvid,
platform: _mobiApp,
).writeToBuffer());
}
static final Map<String, String> headers = {
Headers.contentTypeHeader: 'application/grpc',
'grpc-encoding': 'gzip',

View File

@@ -1,5 +1,6 @@
import 'dart:math';
import 'package:PiliPlus/grpc/grpc_repo.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models/common/dynamics_type.dart';
@@ -26,6 +27,7 @@ class LoginUtils {
static Future onLoginMain() async {
final account = Accounts.main;
GrpcRepo.updateHeaders(account.accessKey);
try {
final cookies = account.cookieJar.toList();
final webManager = web.CookieManager();
@@ -111,6 +113,8 @@ class LoginUtils {
}
static Future onLogoutMain() async {
GrpcRepo.updateHeaders(null);
await Future.wait([
web.CookieManager().deleteAllCookies(),
GStorage.userInfo.delete('userInfoCache'),