Skip to content

Commit

Permalink
🔒 supported 🚀 url func 🦇
Browse files Browse the repository at this point in the history
  • Loading branch information
devfemibadmus committed Aug 16, 2024
1 parent 41edc80 commit 7f4fad3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ Future<String> fetchClipboardContent() async {
return clipboardContent;
}

bool isValidUrl(String value) {
// TODO: url validator
return value.startsWith('https://') || value.startsWith('http://');
bool isSupportUrl(String url) {
final tiktokPattern =
RegExp(r'tiktok\.com/.*/video/(\d+)|tiktok\.com/.*/photo/(\d+)');
final facebookPattern = RegExp(r'facebook\.com/.+');
final instagramPattern = RegExp(r'instagram\.com/.+');

return tiktokPattern.hasMatch(url) ||
facebookPattern.hasMatch(url) ||
instagramPattern.hasMatch(url);
}

Future<String> downloadFile(
Expand Down
4 changes: 2 additions & 2 deletions lib/platforms/webmedia/webmedias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WebMediasState extends State<WebMedias>
setState(() {
mediaData = null;
CustomOverlay().removeOverlayLoader();
if (isValidUrl(value)) {
if (isSupportUrl(value)) {
errorMessage = null;
} else {
errorMessage = 'Not a valid URL';
Expand All @@ -48,7 +48,7 @@ class WebMediasState extends State<WebMedias>
CustomOverlay().showOverlayLoader(context);
});

if (isValidUrl(_textController.text)) {
if (isSupportUrl(_textController.text)) {
final response = await fetchMediaFromServer(_textController.text);

setState(() {
Expand Down
2 changes: 1 addition & 1 deletion lib/platforms/webmedia/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class WebMediaFormState extends State<WebMediaForm> {
}

setState(() {
if (isValidUrl(widget.textController.text)) {
if (isSupportUrl(widget.textController.text)) {
errorMessage = null;
} else {
errorMessage = 'Not a valid URL';
Expand Down

0 comments on commit 7f4fad3

Please sign in to comment.