mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: type & grpc message (#842)
* opt: grpc type * opt: grpc message * opt: http type
This commit is contained in:
committed by
GitHub
parent
7b4f08bb05
commit
024e74115e
@@ -187,73 +187,75 @@ class Request {
|
||||
/*
|
||||
* get请求
|
||||
*/
|
||||
Future<Response> get(url,
|
||||
{queryParameters, options, cancelToken, extra}) async {
|
||||
Response response;
|
||||
if (extra != null) {
|
||||
if (extra['ua'] != null) {
|
||||
options ??= Options();
|
||||
options.headers ??= <String, dynamic>{};
|
||||
options.headers!['user-agent'] = headerUa(type: extra['ua']);
|
||||
}
|
||||
Future<Response> get<T>(
|
||||
String url, {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
CancelToken? cancelToken,
|
||||
String? uaType,
|
||||
}) async {
|
||||
if (uaType != null) {
|
||||
options ??= Options();
|
||||
options.headers ??= <String, dynamic>{};
|
||||
options.headers!['user-agent'] = headerUa(type: uaType);
|
||||
}
|
||||
|
||||
try {
|
||||
response = await dio.get(
|
||||
return await dio.get<T>(
|
||||
url,
|
||||
queryParameters: queryParameters,
|
||||
options: options,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
Response errResponse = Response(
|
||||
return Response(
|
||||
data: {
|
||||
'message': await AccountManager.dioError(e)
|
||||
}, // 将自定义 Map 数据赋值给 Response 的 data 属性
|
||||
statusCode: e.response?.statusCode ?? -1,
|
||||
requestOptions: RequestOptions(),
|
||||
requestOptions: e.requestOptions,
|
||||
);
|
||||
return errResponse;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* post请求
|
||||
*/
|
||||
Future<Response> post(url,
|
||||
{data, queryParameters, options, cancelToken}) async {
|
||||
Future<Response> post<T>(
|
||||
String url, {
|
||||
Object? data,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
// debugPrint('post-data: $data');
|
||||
Response response;
|
||||
try {
|
||||
response = await dio.post(
|
||||
return await dio.post<T>(
|
||||
url,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
options: options,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
// debugPrint('post success: ${response.data}');
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
AccountManager.toast(e);
|
||||
Response errResponse = Response(
|
||||
return Response(
|
||||
data: {
|
||||
'message': await AccountManager.dioError(e)
|
||||
}, // 将自定义 Map 数据赋值给 Response 的 data 属性
|
||||
statusCode: e.response?.statusCode ?? -1,
|
||||
requestOptions: RequestOptions(),
|
||||
requestOptions: e.requestOptions,
|
||||
);
|
||||
return errResponse;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 下载文件
|
||||
*/
|
||||
Future<Response> downloadFile(urlPath, savePath, {cancelToken}) async {
|
||||
Future<Response> downloadFile(String urlPath, String savePath,
|
||||
{CancelToken? cancelToken}) async {
|
||||
try {
|
||||
Response response = await dio.download(
|
||||
final response = await dio.download(
|
||||
urlPath,
|
||||
savePath,
|
||||
cancelToken: cancelToken,
|
||||
@@ -271,7 +273,7 @@ class Request {
|
||||
'message': await AccountManager.dioError(e),
|
||||
},
|
||||
statusCode: e.response?.statusCode ?? -1,
|
||||
requestOptions: RequestOptions(),
|
||||
requestOptions: e.requestOptions,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -286,7 +288,7 @@ class Request {
|
||||
token.cancel("cancelled");
|
||||
}
|
||||
|
||||
static String headerUa({type = 'mob'}) {
|
||||
static String headerUa({String type = 'mob'}) {
|
||||
return switch (type) {
|
||||
'mob' =>
|
||||
'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36',
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:core' hide Error;
|
||||
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
sealed class LoadingState<T> {
|
||||
const LoadingState();
|
||||
|
||||
@@ -11,14 +13,15 @@ sealed class LoadingState<T> {
|
||||
|
||||
T get data => switch (this) {
|
||||
Success(response: final res) => res,
|
||||
Error() => throw this,
|
||||
Loading() => throw Exception('ApiException: loading'),
|
||||
_ => throw this,
|
||||
};
|
||||
|
||||
T? get dataOrNull => switch (this) {
|
||||
Success(response: final res) => res,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
void toast() => SmartDialog.showToast(toString());
|
||||
}
|
||||
|
||||
class Loading extends LoadingState<Never> {
|
||||
@@ -27,6 +30,11 @@ class Loading extends LoadingState<Never> {
|
||||
static const Loading _instance = Loading._internal();
|
||||
|
||||
factory Loading() => _instance;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ApiException: loading';
|
||||
}
|
||||
}
|
||||
|
||||
class Success<T> extends LoadingState<T> {
|
||||
|
||||
@@ -266,7 +266,7 @@ class MemberHttp {
|
||||
}) async {
|
||||
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
||||
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'mid': mid,
|
||||
'token': token,
|
||||
'platform': 'web',
|
||||
@@ -332,7 +332,7 @@ class MemberHttp {
|
||||
}) async {
|
||||
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
||||
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'mid': mid,
|
||||
'ps': ps,
|
||||
'tid': tid,
|
||||
@@ -383,7 +383,7 @@ class MemberHttp {
|
||||
}) async {
|
||||
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
||||
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'mid': mid,
|
||||
'ps': ps,
|
||||
'tid': tid,
|
||||
@@ -426,7 +426,7 @@ class MemberHttp {
|
||||
}) async {
|
||||
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
||||
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'offset': offset ?? '',
|
||||
'host_mid': mid,
|
||||
'timezone_offset': '-480',
|
||||
|
||||
@@ -457,7 +457,7 @@ class MsgHttp {
|
||||
beginSeqno,
|
||||
endSeqno,
|
||||
}) async {
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'talker_id': talkerId,
|
||||
'session_type': 1,
|
||||
'size': 20,
|
||||
@@ -486,7 +486,7 @@ class MsgHttp {
|
||||
int? ackSeqno,
|
||||
}) async {
|
||||
String csrf = Accounts.main.csrf;
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'talker_id': talkerId,
|
||||
'session_type': 1,
|
||||
'ack_seqno': ackSeqno,
|
||||
|
||||
@@ -182,7 +182,7 @@ class VideoHttp {
|
||||
dynamic seasonId,
|
||||
bool? forcePgcApi,
|
||||
}) async {
|
||||
Map<String, dynamic> data = {
|
||||
final params = await WbiSign.makSign({
|
||||
if (avid != null) 'avid': avid,
|
||||
if (bvid != null) 'bvid': bvid,
|
||||
if (epid != null) 'ep_id': epid,
|
||||
@@ -197,15 +197,11 @@ class VideoHttp {
|
||||
'gaia_source': 'pre-load',
|
||||
'isGaiaAvoided': true,
|
||||
'web_location': 1315873,
|
||||
};
|
||||
|
||||
// 免登录查看1080p
|
||||
if (!Accounts.get(AccountType.video).isLogin &&
|
||||
GStorage.setting.get(SettingBoxKey.p1080, defaultValue: true)) {
|
||||
data['try_look'] = 1;
|
||||
}
|
||||
|
||||
Map params = await WbiSign.makSign(data);
|
||||
// 免登录查看1080p
|
||||
if (!Accounts.get(AccountType.video).isLogin &&
|
||||
GStorage.setting.get(SettingBoxKey.p1080, defaultValue: true))
|
||||
'try_look': 1,
|
||||
});
|
||||
|
||||
late final usePgcApi =
|
||||
forcePgcApi == true || Accounts.get(AccountType.video).isLogin;
|
||||
@@ -880,7 +876,7 @@ class VideoHttp {
|
||||
int? cid,
|
||||
int? upMid,
|
||||
}) async {
|
||||
Map params = await WbiSign.makSign({
|
||||
final params = await WbiSign.makSign({
|
||||
'bvid': bvid,
|
||||
'cid': cid,
|
||||
'up_mid': upMid,
|
||||
|
||||
Reference in New Issue
Block a user