mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
@@ -97,7 +97,7 @@ class DynamicsController extends GetxController
|
|||||||
'https:${item.modules.moduleDynamic.major.archive.jumpUrl}';
|
'https:${item.modules.moduleDynamic.major.archive.jumpUrl}';
|
||||||
}
|
}
|
||||||
String? redirectUrl = await UrlUtils.parseRedirectUrl(
|
String? redirectUrl = await UrlUtils.parseRedirectUrl(
|
||||||
item.modules.moduleDynamic.major.archive.jumpUrl);
|
item.modules.moduleDynamic.major.archive.jumpUrl, false);
|
||||||
if (redirectUrl != null) {
|
if (redirectUrl != null) {
|
||||||
Utils.viewPgcFromUri(redirectUrl);
|
Utils.viewPgcFromUri(redirectUrl);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import 'utils.dart';
|
|||||||
|
|
||||||
class UrlUtils {
|
class UrlUtils {
|
||||||
// 302重定向路由截取
|
// 302重定向路由截取
|
||||||
static Future<String?> parseRedirectUrl(String url) async {
|
static Future<String?> parseRedirectUrl(String url,
|
||||||
|
[bool returnOri = false]) async {
|
||||||
try {
|
try {
|
||||||
final response = await Request().get(
|
final response = await Request().get(
|
||||||
url,
|
url,
|
||||||
@@ -20,12 +21,29 @@ class UrlUtils {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 302 || response.statusCode == 301) {
|
if (response.statusCode == 302 || response.statusCode == 301) {
|
||||||
return response.headers['location']?.first;
|
String? redirectUrl = response.headers['location']?.first;
|
||||||
|
if (redirectUrl != null) {
|
||||||
|
if (redirectUrl.endsWith('/')) {
|
||||||
|
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
|
||||||
|
}
|
||||||
|
if (url.contains(redirectUrl)) {
|
||||||
|
if (url.endsWith('/')) {
|
||||||
|
url = url.substring(0, url.length - 1);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
return redirectUrl;
|
||||||
|
} else {
|
||||||
|
if (returnOri && url.endsWith('/')) {
|
||||||
|
url = url.substring(0, url.length - 1);
|
||||||
|
}
|
||||||
|
return returnOri ? url : null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return returnOri ? url : null;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return returnOri ? url : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user