diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/video/upload_video_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/video/upload_video_menu.dart index 80c8cda20a60d..83fa36ceffe6b 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/video/upload_video_menu.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/video/upload_video_menu.dart @@ -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); } diff --git a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart index ea5da4f44a6e8..fb9cd9f226449 100644 --- a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart +++ b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart @@ -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);