Skip to content

Commit

Permalink
fix: use pattern matching for youtube error
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed Jun 2, 2024
1 parent 48a545c commit 2d178db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ class _EmbedUrlState extends State<_EmbedUrl> {
return widget.onSubmit(inputText);
}

if (inputText.startsWith('https://youtube')) {
isYouTubeError = true;
}

isYouTubeError = youtubeUrlRegex.hasMatch(inputText);
setState(() => isUrlValid = false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const _videoUrlPattern =
r'(https?:\/\/)([^\s(["<,>/]*)(\/)[^\s[",><]*(.mp4|.mov|.avi|.webm|.flv|.m4v|.mpeg|.h264)(\?[^\s[",><]*)?';
final videoUrlRegex = RegExp(_videoUrlPattern);

/// This pattern matches both youtube.com and shortened youtu.be urls.
///
const _youtubeUrlPattern = r'^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/';
final youtubeUrlRegex = RegExp(_youtubeUrlPattern);

const _appflowyCloudUrlPattern = r'^(https:\/\/)(.*)(\.appflowy\.cloud\/)(.*)';
final appflowyCloudUrlRegex = RegExp(_appflowyCloudUrlPattern);

Expand Down

0 comments on commit 2d178db

Please sign in to comment.