mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:PiliPlus/http/constants.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class StyleString {
|
class StyleString {
|
||||||
@@ -37,6 +38,15 @@ class Constants {
|
|||||||
static const String statisticsApp =
|
static const String statisticsApp =
|
||||||
'{"appId":1,"platform":3,"version":"8.43.0","abtest":""}';
|
'{"appId":1,"platform":3,"version":"8.43.0","abtest":""}';
|
||||||
|
|
||||||
|
static const baseHeaders = {
|
||||||
|
'connection': 'keep-alive',
|
||||||
|
'accept-encoding': 'br,gzip',
|
||||||
|
'referer': HttpString.baseUrl,
|
||||||
|
'env': 'prod',
|
||||||
|
'app-key': 'android64',
|
||||||
|
'x-bili-aurora-zone': 'sh001',
|
||||||
|
};
|
||||||
|
|
||||||
static final urlRegex = RegExp(
|
static final urlRegex = RegExp(
|
||||||
r'https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]',
|
r'https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:PiliPlus/http/api.dart';
|
|||||||
import 'package:PiliPlus/http/constants.dart';
|
import 'package:PiliPlus/http/constants.dart';
|
||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
|
import 'package:PiliPlus/http/reply.dart';
|
||||||
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
||||||
import 'package:PiliPlus/models/common/reply/reply_option_type.dart';
|
import 'package:PiliPlus/models/common/reply/reply_option_type.dart';
|
||||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||||
@@ -19,7 +20,6 @@ import 'package:PiliPlus/models_new/dynamic/dyn_topic_feed/topic_card_list.dart'
|
|||||||
import 'package:PiliPlus/models_new/dynamic/dyn_topic_top/top_details.dart';
|
import 'package:PiliPlus/models_new/dynamic/dyn_topic_top/top_details.dart';
|
||||||
import 'package:PiliPlus/models_new/dynamic/dyn_topic_top/topic_item.dart';
|
import 'package:PiliPlus/models_new/dynamic/dyn_topic_top/topic_item.dart';
|
||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:PiliPlus/utils/wbi_sign.dart';
|
import 'package:PiliPlus/utils/wbi_sign.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
@@ -232,9 +232,7 @@ class DynamicsHttp {
|
|||||||
'{"platform":"web","device":"pc","spmid":"333.1330"}',
|
'{"platform":"web","device":"pc","spmid":"333.1330"}',
|
||||||
if (!clearCookie && Accounts.main.isLogin) 'csrf': Accounts.main.csrf,
|
if (!clearCookie && Accounts.main.isLogin) 'csrf': Accounts.main.csrf,
|
||||||
},
|
},
|
||||||
options: clearCookie
|
options: clearCookie ? ReplyHttp.options : null,
|
||||||
? Options(extra: {'account': AnonymousAccount(), 'checkReply': true})
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -115,13 +115,7 @@ class Request {
|
|||||||
receiveTimeout: const Duration(milliseconds: 10000),
|
receiveTimeout: const Duration(milliseconds: 10000),
|
||||||
//Http请求头.
|
//Http请求头.
|
||||||
headers: {
|
headers: {
|
||||||
'connection': 'keep-alive',
|
|
||||||
'accept-encoding': 'br,gzip',
|
|
||||||
'user-agent': 'Dart/3.6 (dart:io)', // Http2Adapter不会自动添加标头
|
'user-agent': 'Dart/3.6 (dart:io)', // Http2Adapter不会自动添加标头
|
||||||
'referer': HttpString.baseUrl,
|
|
||||||
'env': 'prod',
|
|
||||||
'app-key': 'android64',
|
|
||||||
'x-bili-aurora-zone': 'sh001',
|
|
||||||
},
|
},
|
||||||
responseDecoder: responseDecoder, // Http2Adapter没有自动解压
|
responseDecoder: responseDecoder, // Http2Adapter没有自动解压
|
||||||
persistentConnection: true,
|
persistentConnection: true,
|
||||||
@@ -205,14 +199,7 @@ class Request {
|
|||||||
Map<String, dynamic>? queryParameters,
|
Map<String, dynamic>? queryParameters,
|
||||||
Options? options,
|
Options? options,
|
||||||
CancelToken? cancelToken,
|
CancelToken? cancelToken,
|
||||||
String? uaType,
|
|
||||||
}) async {
|
}) async {
|
||||||
if (uaType != null) {
|
|
||||||
options ??= Options();
|
|
||||||
options.headers ??= <String, dynamic>{};
|
|
||||||
options.headers!['user-agent'] = headerUa(type: uaType);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await dio.get<T>(
|
return await dio.get<T>(
|
||||||
url,
|
url,
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import 'package:PiliPlus/utils/accounts/account.dart';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
class ReplyHttp {
|
class ReplyHttp {
|
||||||
static final Options _options = Options(
|
static final Options options = Options(
|
||||||
extra: {'account': AnonymousAccount(), 'checkReply': true},
|
headers: {...Constants.baseHeaders, 'cookie': ''},
|
||||||
|
extra: {'account': NoAccount()},
|
||||||
);
|
);
|
||||||
|
|
||||||
static Future<LoadingState> replyList({
|
static Future<LoadingState> replyList({
|
||||||
@@ -36,7 +37,7 @@ class ReplyHttp {
|
|||||||
'{"offset":"${nextOffset.replaceAll('"', '\\"')}"}',
|
'{"offset":"${nextOffset.replaceAll('"', '\\"')}"}',
|
||||||
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
||||||
},
|
},
|
||||||
options: !isLogin ? _options : null,
|
options: !isLogin ? options : null,
|
||||||
)
|
)
|
||||||
: await Request().get(
|
: await Request().get(
|
||||||
Api.replyList,
|
Api.replyList,
|
||||||
@@ -47,7 +48,7 @@ class ReplyHttp {
|
|||||||
'pn': page,
|
'pn': page,
|
||||||
'ps': 20,
|
'ps': 20,
|
||||||
},
|
},
|
||||||
options: !isLogin ? _options : null,
|
options: !isLogin ? options : null,
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
ReplyData replyData = ReplyData.fromJson(res.data['data']);
|
ReplyData replyData = ReplyData.fromJson(res.data['data']);
|
||||||
@@ -155,7 +156,7 @@ class ReplyHttp {
|
|||||||
'sort': 1,
|
'sort': 1,
|
||||||
if (isLogin) 'csrf': Accounts.main.csrf,
|
if (isLogin) 'csrf': Accounts.main.csrf,
|
||||||
},
|
},
|
||||||
options: !isLogin ? _options : null,
|
options: !isLogin ? options : null,
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
ReplyReplyData replyData = ReplyReplyData.fromJson(res.data['data']);
|
ReplyReplyData replyData = ReplyReplyData.fromJson(res.data['data']);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:PiliPlus/common/constants.dart';
|
||||||
import 'package:PiliPlus/models/common/account_type.dart';
|
import 'package:PiliPlus/models/common/account_type.dart';
|
||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
import 'package:PiliPlus/utils/id_utils.dart';
|
import 'package:PiliPlus/utils/id_utils.dart';
|
||||||
@@ -48,9 +49,11 @@ class LoginAccount implements Account {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
late final Map<String, String> headers = {
|
late final Map<String, String> headers = {
|
||||||
|
...Constants.baseHeaders,
|
||||||
'x-bili-mid': _midStr,
|
'x-bili-mid': _midStr,
|
||||||
'x-bili-aurora-eid': IdUtils.genAuroraEid(mid),
|
'x-bili-aurora-eid': IdUtils.genAuroraEid(mid),
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
late String csrf =
|
late String csrf =
|
||||||
cookieJar.domainCookies['bilibili.com']!['/']!['bili_jct']!.cookie.value;
|
cookieJar.domainCookies['bilibili.com']!['/']!['bili_jct']!.cookie.value;
|
||||||
@@ -120,7 +123,7 @@ class AnonymousAccount implements Account {
|
|||||||
@override
|
@override
|
||||||
String csrf = '';
|
String csrf = '';
|
||||||
@override
|
@override
|
||||||
final Map<String, String> headers = const {};
|
final Map<String, String> headers = Constants.baseHeaders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool activited = false;
|
bool activited = false;
|
||||||
@@ -204,3 +207,53 @@ extension BiliCookieJar on DefaultCookieJar {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NoAccount implements Account {
|
||||||
|
@override
|
||||||
|
String? accessKey;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool activited = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
DefaultCookieJar cookieJar = DefaultCookieJar();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String csrf = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? refresh;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Set<AccountType> type = const {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> delete() {
|
||||||
|
return Future.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final Map<String, String> headers = const {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isLogin = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int mid = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onChange() {
|
||||||
|
return Future.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic>? toJson() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
NoAccount._();
|
||||||
|
|
||||||
|
static final _instance = NoAccount._();
|
||||||
|
|
||||||
|
factory NoAccount() => _instance;
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,19 +95,19 @@ class AccountManager extends Interceptor {
|
|||||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||||
final path = options.path;
|
final path = options.path;
|
||||||
|
|
||||||
if (_skipCookie(path)) return handler.next(options);
|
late final Account account = options.extra['account'] ?? _findAccount(path);
|
||||||
|
|
||||||
final Account account = options.extra['account'] ?? _findAccount(path);
|
if (_skipCookie(path) || account is NoAccount) return handler.next(options);
|
||||||
|
|
||||||
if (account.isLogin) {
|
if (!account.isLogin && path == Api.heartBeat) {
|
||||||
options.headers.addAll(account.headers);
|
|
||||||
} else if (path == Api.heartBeat) {
|
|
||||||
return handler.reject(
|
return handler.reject(
|
||||||
DioException.requestCancelled(requestOptions: options, reason: null),
|
DioException.requestCancelled(requestOptions: options, reason: null),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.headers.addAll(account.headers);
|
||||||
|
|
||||||
// app端不需要管理cookie
|
// app端不需要管理cookie
|
||||||
if (path.startsWith(HttpString.appBaseUrl)) {
|
if (path.startsWith(HttpString.appBaseUrl)) {
|
||||||
// if (kDebugMode) debugPrint('is app: ${options.path}');
|
// if (kDebugMode) debugPrint('is app: ${options.path}');
|
||||||
@@ -130,11 +130,6 @@ class AccountManager extends Interceptor {
|
|||||||
}
|
}
|
||||||
return handler.next(options);
|
return handler.next(options);
|
||||||
} else {
|
} else {
|
||||||
if (account is AnonymousAccount && options.extra['checkReply'] == true) {
|
|
||||||
options.headers[HttpHeaders.cookieHeader] = '';
|
|
||||||
handler.next(options);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
account.cookieJar
|
account.cookieJar
|
||||||
.loadForRequest(options.uri)
|
.loadForRequest(options.uri)
|
||||||
.then((cookies) {
|
.then((cookies) {
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import 'dart:io' show Platform;
|
|||||||
import 'package:PiliPlus/build_config.dart';
|
import 'package:PiliPlus/build_config.dart';
|
||||||
import 'package:PiliPlus/http/api.dart';
|
import 'package:PiliPlus/http/api.dart';
|
||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
|
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||||
import 'package:PiliPlus/utils/page_utils.dart';
|
import 'package:PiliPlus/utils/page_utils.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:PiliPlus/utils/storage_key.dart';
|
import 'package:PiliPlus/utils/storage_key.dart';
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
@@ -17,7 +19,13 @@ class Update {
|
|||||||
if (kDebugMode) return;
|
if (kDebugMode) return;
|
||||||
SmartDialog.dismiss();
|
SmartDialog.dismiss();
|
||||||
try {
|
try {
|
||||||
final res = await Request().get(Api.latestApp, uaType: 'mob');
|
final res = await Request().get(
|
||||||
|
Api.latestApp,
|
||||||
|
options: Options(
|
||||||
|
headers: {'user-agent': Request.headerUa()},
|
||||||
|
extra: {'account': NoAccount()},
|
||||||
|
),
|
||||||
|
);
|
||||||
if (res.data is Map || res.data.isEmpty) {
|
if (res.data is Map || res.data.isEmpty) {
|
||||||
if (!isAuto) {
|
if (!isAuto) {
|
||||||
SmartDialog.showToast('检查更新失败,GitHub接口未返回数据,请检查网络');
|
SmartDialog.showToast('检查更新失败,GitHub接口未返回数据,请检查网络');
|
||||||
|
|||||||
Reference in New Issue
Block a user