opt: better url pattern

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-13 21:33:52 +08:00
parent 84cc65489f
commit 7dd47736fb
6 changed files with 19 additions and 11 deletions

View File

@@ -26,6 +26,9 @@ class Constants {
'%7B%22appId%22%3A5%2C%22platform%22%3A3%2C%22version%22%3A%221.46.2%22%2C%22abtest%22%3A%22%22%7D';
//Uri.encodeComponent('{"appId": 5,"platform": 3,"version": "1.46.2","abtest": ""}');
static const urlPattern =
r'https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]';
// 超分辨率滤镜
static const List<String> mpvAnime4KShaders = [
'Anime4K_Clamp_Highlights.glsl',

View File

@@ -1002,8 +1002,10 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
switch (currentDesc.type) {
case 1:
final List<InlineSpan> spanChildren = <InlineSpan>[];
final RegExp urlRegExp =
RegExp(r'https?://\S+\b|av\d+|bv\S+\b', caseSensitive: false);
final RegExp urlRegExp = RegExp(
'${Constants.urlPattern}|av\\d+|bv\\S+\\b',
caseSensitive: false,
);
(currentDesc.rawText as String).splitMapJoin(
urlRegExp,

View File

@@ -1,3 +1,4 @@
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
@@ -147,7 +148,7 @@ class IntroDetail extends StatelessWidget {
switch (currentDesc.type) {
case 1:
final List<InlineSpan> spanChildren = <InlineSpan>[];
final RegExp urlRegExp = RegExp(r'https?://\S+\b');
final RegExp urlRegExp = RegExp(Constants.urlPattern);
final Iterable<Match> matches =
urlRegExp.allMatches(currentDesc.rawText);

View File

@@ -1,5 +1,6 @@
import 'dart:math';
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/imageview.dart';
import 'package:PiliPlus/http/video.dart';
import 'package:PiliPlus/models/dynamics/result.dart';
@@ -704,7 +705,7 @@ class ReplyItem extends StatelessWidget {
if (jumpUrlKeysList.isNotEmpty) {
patternStr += '|${jumpUrlKeysList.map(RegExp.escape).join('|')}';
}
patternStr += r'|https?://\S+\b';
patternStr += '|${Constants.urlPattern}';
final RegExp pattern = RegExp(patternStr);
List<String> matchedStrs = [];
void addPlainTextSpan(str) {
@@ -896,10 +897,10 @@ class ReplyItem extends StatelessWidget {
},
),
);
} else if (RegExp(r'https?://\S+\b').hasMatch(matchStr)) {
} else if (RegExp(Constants.urlPattern).hasMatch(matchStr)) {
spanChildren.add(
TextSpan(
text: ' $matchStr ',
text: matchStr,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),

View File

@@ -1,5 +1,6 @@
import 'dart:math';
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/badge.dart';
import 'package:PiliPlus/common/widgets/imageview.dart';
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
@@ -101,7 +102,6 @@ class ReplyItemGrpc extends StatelessWidget {
);
Widget _buildContent(context) {
print(replyItem.member.garbCardImage);
return Column(
children: [
if (ModuleAuthorModel.showDynDecorate &&
@@ -745,7 +745,7 @@ class ReplyItemGrpc extends StatelessWidget {
if (jumpUrlKeysList.isNotEmpty) {
patternStr += '|${jumpUrlKeysList.map(RegExp.escape).join('|')}';
}
patternStr += r'|https?://\S+\b';
patternStr += '|${Constants.urlPattern}';
final RegExp pattern = RegExp(patternStr);
List<String> matchedStrs = [];
void addPlainTextSpan(str) {
@@ -934,10 +934,10 @@ class ReplyItemGrpc extends StatelessWidget {
},
),
);
} else if (RegExp(r'https?://\S+\b').hasMatch(matchStr)) {
} else if (RegExp(Constants.urlPattern).hasMatch(matchStr)) {
spanChildren.add(
TextSpan(
text: ' $matchStr ',
text: matchStr,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),

View File

@@ -1,3 +1,4 @@
import 'package:PiliPlus/common/constants.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@@ -171,7 +172,7 @@ class AiDetail extends StatelessWidget {
switch (currentDesc.type) {
case 1:
List<InlineSpan> spanChildren = [];
RegExp urlRegExp = RegExp(r'https?://\S+\b');
RegExp urlRegExp = RegExp(Constants.urlPattern);
Iterable<Match> matches = urlRegExp.allMatches(currentDesc.rawText);
int previousEndIndex = 0;