mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-15 21:53:59 +08:00
opt: post redirect
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -222,7 +222,7 @@ class Request {
|
|||||||
* post请求
|
* post请求
|
||||||
*/
|
*/
|
||||||
Future<Response> post(url,
|
Future<Response> post(url,
|
||||||
{data, queryParameters, options, cancelToken, extra}) async {
|
{data, queryParameters, options, cancelToken, isRedirect}) async {
|
||||||
// debugPrint('post-data: $data');
|
// debugPrint('post-data: $data');
|
||||||
Response response;
|
Response response;
|
||||||
try {
|
try {
|
||||||
@@ -236,6 +236,21 @@ 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);
|
||||||
Response errResponse = Response(
|
Response errResponse = Response(
|
||||||
data: {
|
data: {
|
||||||
'message': await AccountManager.dioError(e)
|
'message': await AccountManager.dioError(e)
|
||||||
|
|||||||
@@ -535,8 +535,7 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onPost({String? url}) async {
|
void _onPost({String? url}) async {
|
||||||
Request()
|
Request().post(
|
||||||
.post(
|
|
||||||
url ?? '${GStorage.blockServer}/api/skipSegments',
|
url ?? '${GStorage.blockServer}/api/skipSegments',
|
||||||
data: {
|
data: {
|
||||||
'videoID': videoDetailController.bvid,
|
'videoID': videoDetailController.bvid,
|
||||||
@@ -558,10 +557,13 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
.toList(),
|
.toList(),
|
||||||
},
|
},
|
||||||
options: Options(
|
options: Options(
|
||||||
validateStatus: (status) => true,
|
validateStatus: (int? status) {
|
||||||
|
return status != null &&
|
||||||
|
((status >= 200 && status < 300) ||
|
||||||
|
const [400, 403, 429, 409].contains(status));
|
||||||
|
},
|
||||||
),
|
),
|
||||||
)
|
).then(
|
||||||
.then(
|
|
||||||
(res) {
|
(res) {
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
Get.back();
|
Get.back();
|
||||||
@@ -574,15 +576,8 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
|||||||
videoDetailController.initSkip();
|
videoDetailController.initSkip();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (const [301, 302, 303, 307, 308].contains(res.statusCode)) {
|
|
||||||
String? redirectUrl = res.headers['location']?.firstOrNull;
|
|
||||||
if (redirectUrl != null) {
|
|
||||||
_onPost(url: redirectUrl);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SmartDialog.showToast(
|
SmartDialog.showToast(
|
||||||
'提交失败: ${{
|
'提交失败: ${const {
|
||||||
400: '参数错误',
|
400: '参数错误',
|
||||||
403: '被自动审核机制拒绝',
|
403: '被自动审核机制拒绝',
|
||||||
429: '重复提交太快',
|
429: '重复提交太快',
|
||||||
|
|||||||
@@ -170,7 +170,28 @@ class AccountManager extends Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
void onError(DioException err, ErrorInterceptorHandler handler) async {
|
||||||
|
if (err.requestOptions.method != 'POST') {
|
||||||
|
toast(err);
|
||||||
|
}
|
||||||
|
if (err.response != null &&
|
||||||
|
!err.response!.requestOptions.path.startsWith(HttpString.appBaseUrl)) {
|
||||||
|
_saveCookies(err.response!).then((_) => handler.next(err)).catchError(
|
||||||
|
(dynamic e, StackTrace s) {
|
||||||
|
final error = DioException(
|
||||||
|
requestOptions: err.response!.requestOptions,
|
||||||
|
error: e,
|
||||||
|
stackTrace: s,
|
||||||
|
);
|
||||||
|
handler.next(error);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
handler.next(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toast(err) {
|
||||||
const List<String> skipShow = [
|
const List<String> skipShow = [
|
||||||
'heartbeat',
|
'heartbeat',
|
||||||
'history/report',
|
'history/report',
|
||||||
@@ -190,22 +211,6 @@ class AccountManager extends Interceptor {
|
|||||||
} else {
|
} else {
|
||||||
dioError(err).then((res) => SmartDialog.showToast(res + url));
|
dioError(err).then((res) => SmartDialog.showToast(res + url));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.response != null &&
|
|
||||||
!err.response!.requestOptions.path.startsWith(HttpString.appBaseUrl)) {
|
|
||||||
_saveCookies(err.response!).then((_) => handler.next(err)).catchError(
|
|
||||||
(dynamic e, StackTrace s) {
|
|
||||||
final error = DioException(
|
|
||||||
requestOptions: err.response!.requestOptions,
|
|
||||||
error: e,
|
|
||||||
stackTrace: s,
|
|
||||||
);
|
|
||||||
handler.next(error);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
handler.next(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveCookies(Response response) async {
|
Future<void> _saveCookies(Response response) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user