From ed18f470274a1f1d3af07a180930e284e92fbeb2 Mon Sep 17 00:00:00 2001 From: rawnly Date: Tue, 26 Sep 2023 13:18:04 +0200 Subject: [PATCH] fix: fixed the url parser --- cmd/root.go | 5 +++++ lib/expressions/expressions.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index e634379..26a6b8d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -152,6 +152,11 @@ var rootCmd = &cobra.Command{ handleSpinnerError(err, connectionSpinner, cmd, ConnectionSpinnerSuffix[1]) } else if idFlag != "" { idFlag = lib.ParsePhotoIDFromUrl(idFlag) + + fmt.Println(idFlag) + + return + photo, err = api.GetPhoto(idFlag) handleSpinnerError(err, connectionSpinner, cmd, ConnectionSpinnerSuffix[1]) } else { diff --git a/lib/expressions/expressions.go b/lib/expressions/expressions.go index 96ee75d..7a4ceb5 100644 --- a/lib/expressions/expressions.go +++ b/lib/expressions/expressions.go @@ -4,7 +4,7 @@ import "regexp" const ( CollectionIdExtractor string = "unsplash\\.com\\/collections\\/([A-z0-9]+)\\/([a-z\\-]+)\\/?$" - PhotoIdExtractor string = "unsplash\\.com\\/photos\\/([A-z0-9]+)\\/?$" + PhotoIdExtractor string = "https?:\\/\\/unsplash\\.com\\/photos\\/(\\w+-)+(\\w+)$" ) func IsPhotoUrl(url string) bool { @@ -23,7 +23,7 @@ func ExtractPhotoId(url string) string { re := regexp.MustCompile(PhotoIdExtractor) if re.MatchString(url) { - return re.FindStringSubmatch(url)[1] + return re.FindStringSubmatch(url)[2] } return ""