From d728b1fb6d74ee535b57f1ca0dc87f056789387c Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 5 Mar 2024 23:39:05 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E8=AF=84=E8=AE=BA=E5=8C=BA=E9=9D=9E?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=9C=B0=E5=9D=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/reply/widgets/reply_item.dart | 5 ++++ lib/utils/url_utils.dart | 24 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 174cfabb..f9f695d4 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -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; diff --git a/lib/utils/url_utils.dart b/lib/utils/url_utils.dart index bac6cdfa..cf0ef9e2 100644 --- a/lib/utils/url_utils.dart +++ b/lib/utils/url_utils.dart @@ -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路由跳转