Skip to content

Commit

Permalink
mod: 评论区非正常地址判断
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Mar 5, 2024
1 parent 12e947e commit d728b1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/pages/video/detail/reply/widgets/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ InlineSpan buildContent(
} else {
final String redirectUrl =
await UrlUtils.parseRedirectUrl(matchStr);
if (redirectUrl == matchStr) {
Clipboard.setData(ClipboardData(text: matchStr));
SmartDialog.showToast('地址可能有误');
return;
}
final String pathSegment = Uri.parse(redirectUrl).path;
final String lastPathSegment =
pathSegment.split('/').last;
Expand Down
24 changes: 14 additions & 10 deletions lib/utils/url_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ class UrlUtils {
dio.options.validateStatus = (status) {
return status == 200 || status == 301 || status == 302;
};
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);
}
} else {
if (url.endsWith('/')) {
url = url.substring(0, url.length - 1);
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);
}
} else {
if (url.endsWith('/')) {
url = url.substring(0, url.length - 1);
}
return url;
}
return redirectUrl;
} catch (err) {
return url;
}
return redirectUrl;
}

// 匹配url路由跳转
Expand Down

0 comments on commit d728b1f

Please sign in to comment.