opt: handle url

Closes #143

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-12 09:27:36 +08:00
parent 0817b183a4
commit e645274609
4 changed files with 45 additions and 26 deletions

View File

@@ -777,7 +777,6 @@ class ReplyItem extends StatelessWidget {
if (matchStr.startsWith('BV')) { if (matchStr.startsWith('BV')) {
UrlUtils.matchUrlPush( UrlUtils.matchUrlPush(
matchStr, matchStr,
title,
'', '',
); );
} else if (RegExp(r'^[Cc][Vv][0-9]+$') } else if (RegExp(r'^[Cc][Vv][0-9]+$')
@@ -834,7 +833,6 @@ class ReplyItem extends StatelessWidget {
if (lastPathSegment.startsWith('BV')) { if (lastPathSegment.startsWith('BV')) {
UrlUtils.matchUrlPush( UrlUtils.matchUrlPush(
lastPathSegment, lastPathSegment,
title,
redirectUrl, redirectUrl,
); );
} else { } else {
@@ -876,7 +874,26 @@ class ReplyItem extends StatelessWidget {
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () => Utils.handleWebview(matchStr), ..onTap = () async {
if (matchStr.startsWith('https://b23.tv')) {
final String redirectUrl =
(await UrlUtils.parseRedirectUrl(matchStr)) ??
matchStr;
final String pathSegment = Uri.parse(redirectUrl).path;
final String lastPathSegment =
pathSegment.split('/').last;
if (lastPathSegment.startsWith('BV')) {
UrlUtils.matchUrlPush(
lastPathSegment,
redirectUrl,
);
} else {
PiliScheme.routePush(Uri.parse(matchStr));
}
} else {
PiliScheme.routePush(Uri.parse(matchStr));
}
},
), ),
); );
} else { } else {

View File

@@ -809,7 +809,6 @@ class ReplyItemGrpc extends StatelessWidget {
if (matchStr.startsWith('BV')) { if (matchStr.startsWith('BV')) {
UrlUtils.matchUrlPush( UrlUtils.matchUrlPush(
matchStr, matchStr,
title,
'', '',
); );
} else if (RegExp(r'^[Cc][Vv][0-9]+$') } else if (RegExp(r'^[Cc][Vv][0-9]+$')
@@ -866,7 +865,6 @@ class ReplyItemGrpc extends StatelessWidget {
if (lastPathSegment.startsWith('BV')) { if (lastPathSegment.startsWith('BV')) {
UrlUtils.matchUrlPush( UrlUtils.matchUrlPush(
lastPathSegment, lastPathSegment,
title,
redirectUrl, redirectUrl,
); );
} else { } else {
@@ -908,7 +906,26 @@ class ReplyItemGrpc extends StatelessWidget {
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () => Utils.handleWebview(matchStr), ..onTap = () async {
if (matchStr.startsWith('https://b23.tv')) {
final String redirectUrl =
(await UrlUtils.parseRedirectUrl(matchStr)) ??
matchStr;
final String pathSegment = Uri.parse(redirectUrl).path;
final String lastPathSegment =
pathSegment.split('/').last;
if (lastPathSegment.startsWith('BV')) {
UrlUtils.matchUrlPush(
lastPathSegment,
redirectUrl,
);
} else {
PiliScheme.routePush(Uri.parse(matchStr));
}
} else {
PiliScheme.routePush(Uri.parse(matchStr));
}
},
), ),
); );
} else { } else {

View File

@@ -201,7 +201,7 @@ class PiliScheme {
//Utils.toDupNamed( //Utils.toDupNamed(
// '/webview', // '/webview',
// parameters: { // parameters: {
// 'url': value.dataString ?? "", // 'url': ,
// 'type': 'url', // 'type': 'url',
// 'pageTitle': '' // 'pageTitle': ''
// }, // },
@@ -336,24 +336,17 @@ class PiliScheme {
} else if (lastPathSegment.startsWith('BV')) { } else if (lastPathSegment.startsWith('BV')) {
UrlUtils.matchUrlPush( UrlUtils.matchUrlPush(
lastPathSegment, lastPathSegment,
'',
redirectUrl, redirectUrl,
); );
} else { } else {
Utils.toDupNamed( Utils.handleWebview(redirectUrl);
'/webview',
parameters: {'url': redirectUrl, 'type': 'url', 'pageTitle': ''},
);
} }
return; return;
} }
List<String> pathPart = path.split('/'); List<String> pathPart = path.split('/');
if (pathPart.length < 3) { if (pathPart.length < 3) {
Utils.toDupNamed( Utils.handleWebview(value.toString());
'/webview',
parameters: {'url': value.toString()},
);
return; return;
} }
final String area = pathPart[1] == 'mobile' ? pathPart[2] : pathPart[1]; final String area = pathPart[1] == 'mobile' ? pathPart[2] : pathPart[1];
@@ -409,15 +402,8 @@ class PiliScheme {
} else if (res.containsKey('BV')) { } else if (res.containsKey('BV')) {
videoPush(null, res['BV'] as String); videoPush(null, res['BV'] as String);
} else { } else {
SmartDialog.showToast('未知路径或匹配错误:$value,先采用浏览器打开'); // SmartDialog.showToast('未知路径或匹配错误:$value先采用浏览器打开');
Utils.toDupNamed( Utils.handleWebview(value.toString());
'/webview',
parameters: {
'url': value.toString(),
'type': 'url',
'pageTitle': ''
},
);
} }
} }
} }

View File

@@ -50,7 +50,6 @@ class UrlUtils {
// 匹配url路由跳转 // 匹配url路由跳转
static matchUrlPush( static matchUrlPush(
String pathSegment, String pathSegment,
String title,
String redirectUrl, String redirectUrl,
) async { ) async {
final Map matchRes = IdUtils.matchAvorBv(input: pathSegment); final Map matchRes = IdUtils.matchAvorBv(input: pathSegment);