Skip to content

Commit

Permalink
fix: fixed the url parser
Browse files Browse the repository at this point in the history
fix: fixed the url parser
  • Loading branch information
rawnly committed Sep 26, 2023
2 parents 717565c + ed18f47 commit 3d51229
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/expressions/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 ""
Expand Down

0 comments on commit 3d51229

Please sign in to comment.