mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-06 21:22:36 +00:00
feat: support multiple type shortcuts link
This commit is contained in:
@ -8,7 +8,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/boojack/shortify/internal/util"
|
||||
"github.com/boojack/shortify/store"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@ -86,9 +85,6 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(create); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post shortcut request").SetInternal(err)
|
||||
}
|
||||
if !validateLink(create.Link) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid link: %s", create.Link))
|
||||
}
|
||||
|
||||
shortcut, err := s.Store.CreateShortcut(ctx, &store.Shortcut{
|
||||
CreatorID: userID,
|
||||
@ -151,9 +147,6 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
||||
name := strings.ToLower(*patch.Name)
|
||||
patch.Name = &name
|
||||
}
|
||||
if patch.Link != nil && !validateLink(*patch.Link) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid link: %s", *patch.Link))
|
||||
}
|
||||
|
||||
shortcutUpdate := &store.UpdateShortcut{
|
||||
ID: shortcutID,
|
||||
@ -369,7 +362,3 @@ func convertShortcutFromStore(shortcut *store.Shortcut) *Shortcut {
|
||||
Tags: tags,
|
||||
}
|
||||
}
|
||||
|
||||
func validateLink(link string) bool {
|
||||
return util.HasPrefixes(link, "http://", "https://")
|
||||
}
|
||||
|
Reference in New Issue
Block a user