opt: view pgc from dynamic

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-09 21:47:31 +08:00
parent 9ab6dcff23
commit 57043166a9
6 changed files with 42 additions and 25 deletions

View File

@@ -1,35 +1,31 @@
import 'package:dio/dio.dart';
import 'package:get/get.dart';
import '../http/init.dart';
import '../http/search.dart';
import 'id_utils.dart';
import 'utils.dart';
class UrlUtils {
// 302重定向路由截取
static Future<String> parseRedirectUrl(String url) async {
late String redirectUrl;
final dio = Dio();
dio.options.followRedirects = false;
dio.options.validateStatus = (status) {
return status == 200 || status == 301 || status == 302;
};
static Future<String?> parseRedirectUrl(String url) async {
try {
final response = await dio.get(url);
if (response.statusCode == 302) {
redirectUrl = response.headers['location']?.first as String;
if (redirectUrl.endsWith('/')) {
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
}
final response = await Request().get(
url,
options: Options(
followRedirects: false,
validateStatus: (status) {
return status == 200 || status == 301 || status == 302;
},
),
);
if (response.statusCode == 302 || response.statusCode == 301) {
return response.headers['location']?.first;
} else {
if (url.endsWith('/')) {
url = url.substring(0, url.length - 1);
}
return url;
return null;
}
return redirectUrl;
} catch (err) {
return url;
return null;
}
}