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:
@ -3,6 +3,7 @@ package v1
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/boojack/shortify/store"
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -39,7 +40,10 @@ func (s *APIV1Service) registerRedirectorRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
||||
}
|
||||
|
||||
return c.Redirect(http.StatusSeeOther, shortcut.Link)
|
||||
if isValidURLString(shortcut.Link) {
|
||||
return c.Redirect(http.StatusSeeOther, shortcut.Link)
|
||||
}
|
||||
return c.String(http.StatusOK, shortcut.Link)
|
||||
})
|
||||
}
|
||||
|
||||
@ -66,3 +70,8 @@ func (s *APIV1Service) createShortcutViewActivity(c echo.Context, shortcut *stor
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isValidURLString(s string) bool {
|
||||
_, err := url.ParseRequestURI(s)
|
||||
return err == nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user