mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
committed by
GitHub
parent
a46bde68f5
commit
c090cae1a1
@@ -164,10 +164,8 @@ class Request {
|
|||||||
: http11Adapter;
|
: http11Adapter;
|
||||||
|
|
||||||
// 先于其他Interceptor
|
// 先于其他Interceptor
|
||||||
if (GStorage.retryCount > 0) {
|
dio.interceptors
|
||||||
dio.interceptors
|
.add(RetryInterceptor(GStorage.retryCount, GStorage.retryDelay));
|
||||||
.add(RetryInterceptor(GStorage.retryCount, GStorage.retryDelay));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 日志拦截器 输出请求、响应内容
|
// 日志拦截器 输出请求、响应内容
|
||||||
if (BuildConfig.isDebug) {
|
if (BuildConfig.isDebug) {
|
||||||
@@ -222,7 +220,7 @@ class Request {
|
|||||||
* post请求
|
* post请求
|
||||||
*/
|
*/
|
||||||
Future<Response> post(url,
|
Future<Response> post(url,
|
||||||
{data, queryParameters, options, cancelToken, isRedirect}) async {
|
{data, queryParameters, options, cancelToken}) async {
|
||||||
// debugPrint('post-data: $data');
|
// debugPrint('post-data: $data');
|
||||||
Response response;
|
Response response;
|
||||||
try {
|
try {
|
||||||
@@ -236,20 +234,6 @@ class Request {
|
|||||||
// debugPrint('post success: ${response.data}');
|
// debugPrint('post success: ${response.data}');
|
||||||
return response;
|
return response;
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
if (isRedirect != true &&
|
|
||||||
const [301, 302, 303, 307, 308].contains(e.response?.statusCode)) {
|
|
||||||
String? redirectUrl = e.response?.headers['location']?.firstOrNull;
|
|
||||||
if (redirectUrl != null) {
|
|
||||||
return await post(
|
|
||||||
redirectUrl,
|
|
||||||
data: data,
|
|
||||||
queryParameters: queryParameters,
|
|
||||||
options: options,
|
|
||||||
cancelToken: cancelToken,
|
|
||||||
isRedirect: true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AccountManager.toast(e);
|
AccountManager.toast(e);
|
||||||
Response errResponse = Response(
|
Response errResponse = Response(
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -35,10 +35,8 @@ class LiveHttp {
|
|||||||
'origin': 'https://live.bilibili.com',
|
'origin': 'https://live.bilibili.com',
|
||||||
'referer': 'https://live.bilibili.com/',
|
'referer': 'https://live.bilibili.com/',
|
||||||
'user-agent': Request.headerUa(type: 'pc'),
|
'user-agent': Request.headerUa(type: 'pc'),
|
||||||
|
if (gaiaVtoken == null) 'cookie': 'x-bili-gaia-vtoken=$gaiaVtoken'
|
||||||
},
|
},
|
||||||
extra: gaiaVtoken == null
|
|
||||||
? null
|
|
||||||
: {'cookie': 'x-bili-gaia-vtoken=$gaiaVtoken'},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
|
|||||||
@@ -10,26 +10,56 @@ class RetryInterceptor extends Interceptor {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||||
if (err.response != null) return handler.next(err);
|
if (err.response != null) {
|
||||||
switch (err.type) {
|
final options = err.requestOptions;
|
||||||
case DioExceptionType.connectionError:
|
if (options.followRedirects && options.maxRedirects > 0) {
|
||||||
case DioExceptionType.connectionTimeout:
|
final status = err.response!.statusCode;
|
||||||
case DioExceptionType.sendTimeout:
|
if (status != null && 300 <= status && status < 400) {
|
||||||
case DioExceptionType.unknown:
|
var redirectUrl = err.response!.headers.value('location');
|
||||||
if ((err.requestOptions.extra['_rt'] ??= 0) < _count) {
|
if (redirectUrl != null) {
|
||||||
Future.delayed(
|
var uri = Uri.parse(redirectUrl);
|
||||||
Duration(
|
if (!uri.hasScheme) {
|
||||||
milliseconds: ++err.requestOptions.extra['_rt'] * _delay),
|
uri = options.uri.resolveUri(uri);
|
||||||
() => Request.dio
|
redirectUrl = uri.toString();
|
||||||
.fetch(err.requestOptions)
|
}
|
||||||
.then(handler.resolve)
|
(options..path = redirectUrl).maxRedirects--;
|
||||||
.onError<DioException>((error, _) => handler.reject(error)));
|
if (status == 303) {
|
||||||
} else {
|
options.data = null;
|
||||||
handler.next(err);
|
options.method = 'GET';
|
||||||
|
}
|
||||||
|
Request.dio
|
||||||
|
.fetch(options)
|
||||||
|
.then((i) => handler.resolve(i
|
||||||
|
..redirects.add(RedirectRecord(status, options.method, uri))
|
||||||
|
..isRedirect = true))
|
||||||
|
.onError<DioException>((error, _) => handler.next(error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
default:
|
return handler.next(err);
|
||||||
return handler.next(err);
|
} else {
|
||||||
|
switch (err.type) {
|
||||||
|
case DioExceptionType.connectionError:
|
||||||
|
case DioExceptionType.connectionTimeout:
|
||||||
|
case DioExceptionType.sendTimeout:
|
||||||
|
case DioExceptionType.unknown:
|
||||||
|
if ((err.requestOptions.extra['_rt'] ??= 0) < _count) {
|
||||||
|
Future.delayed(
|
||||||
|
Duration(
|
||||||
|
milliseconds: ++err.requestOptions.extra['_rt'] * _delay),
|
||||||
|
() => Request.dio
|
||||||
|
.fetch(err.requestOptions)
|
||||||
|
.then(handler.resolve)
|
||||||
|
.onError<DioException>(
|
||||||
|
(error, _) => handler.reject(error)));
|
||||||
|
} else {
|
||||||
|
handler.next(err);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return handler.next(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -535,8 +535,8 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onPost({String? url}) async {
|
Future _onPost({String? url}) {
|
||||||
Request().post(
|
return Request().post(
|
||||||
url ?? '${GStorage.blockServer}/api/skipSegments',
|
url ?? '${GStorage.blockServer}/api/skipSegments',
|
||||||
data: {
|
data: {
|
||||||
'videoID': videoDetailController.bvid,
|
'videoID': videoDetailController.bvid,
|
||||||
@@ -557,14 +557,9 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
},
|
},
|
||||||
options: Options(
|
options: Options(followRedirects: true),
|
||||||
validateStatus: (int? status) {
|
)
|
||||||
return status != null &&
|
.then(
|
||||||
((status >= 200 && status < 300) ||
|
|
||||||
const [400, 403, 429, 409].contains(status));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
).then(
|
|
||||||
(res) {
|
(res) {
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
Get.back();
|
Get.back();
|
||||||
@@ -578,12 +573,13 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast(
|
SmartDialog.showToast(
|
||||||
'提交失败: ${const {
|
'提交失败: ${switch (res.statusCode) {
|
||||||
400: '参数错误',
|
400 => '参数错误',
|
||||||
403: '被自动审核机制拒绝',
|
403 => '被自动审核机制拒绝',
|
||||||
429: '重复提交太快',
|
429 => '重复提交太快',
|
||||||
409: '重复提交'
|
409 => '重复提交',
|
||||||
}[res.statusCode] ?? res.statusCode}',
|
_ => res.statusCode.toString()
|
||||||
|
}}',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -129,20 +129,13 @@ class AccountManager extends Interceptor {
|
|||||||
account.cookieJar.loadForRequest(options.uri).then((cookies) {
|
account.cookieJar.loadForRequest(options.uri).then((cookies) {
|
||||||
final previousCookies =
|
final previousCookies =
|
||||||
options.headers[HttpHeaders.cookieHeader] as String?;
|
options.headers[HttpHeaders.cookieHeader] as String?;
|
||||||
String newCookies = getCookies([
|
final newCookies = getCookies([
|
||||||
...?previousCookies
|
...?previousCookies
|
||||||
?.split(';')
|
?.split(';')
|
||||||
.where((e) => e.isNotEmpty)
|
.where((e) => e.isNotEmpty)
|
||||||
.map((c) => Cookie.fromSetCookieValue(c)),
|
.map((c) => Cookie.fromSetCookieValue(c)),
|
||||||
...cookies,
|
...cookies,
|
||||||
]);
|
]);
|
||||||
if (options.extra['cookie'] != null) {
|
|
||||||
if (newCookies.isEmpty) {
|
|
||||||
newCookies = '${options.extra['cookie']}';
|
|
||||||
} else {
|
|
||||||
newCookies += ';${options.extra['cookie']}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
options.headers[HttpHeaders.cookieHeader] =
|
options.headers[HttpHeaders.cookieHeader] =
|
||||||
newCookies.isNotEmpty ? newCookies : '';
|
newCookies.isNotEmpty ? newCookies : '';
|
||||||
handler.next(options);
|
handler.next(options);
|
||||||
@@ -177,7 +170,7 @@ class AccountManager extends Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onError(DioException err, ErrorInterceptorHandler handler) async {
|
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||||
if (err.requestOptions.method != 'POST') {
|
if (err.requestOptions.method != 'POST') {
|
||||||
toast(err);
|
toast(err);
|
||||||
}
|
}
|
||||||
@@ -198,7 +191,7 @@ class AccountManager extends Interceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toast(err) {
|
static void toast(DioException err) {
|
||||||
const List<String> skipShow = [
|
const List<String> skipShow = [
|
||||||
'heartbeat',
|
'heartbeat',
|
||||||
'history/report',
|
'history/report',
|
||||||
|
|||||||
Reference in New Issue
Block a user