mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-12 19:01:50 +02:00
Add custom urls for gists (#183)
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
"golang.org/x/crypto/argon2"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -135,6 +136,8 @@ type OpengistValidator struct {
|
||||
func NewValidator() *OpengistValidator {
|
||||
v := validator.New()
|
||||
_ = v.RegisterValidation("notreserved", validateReservedKeywords)
|
||||
_ = v.RegisterValidation("alphanumdash", validateAlphaNumDash)
|
||||
_ = v.RegisterValidation("alphanumdashorempty", validateAlphaNumDashOrEmpty)
|
||||
return &OpengistValidator{v}
|
||||
}
|
||||
|
||||
@ -158,6 +161,9 @@ func validationMessages(err *error) string {
|
||||
messages[i] = e.Field() + " should not include a sub directory"
|
||||
case "alphanum":
|
||||
messages[i] = e.Field() + " should only contain alphanumeric characters"
|
||||
case "alphanumdash":
|
||||
case "alphanumdashorempty":
|
||||
messages[i] = e.Field() + " should only contain alphanumeric characters and dashes"
|
||||
case "min":
|
||||
messages[i] = "Not enough " + e.Field()
|
||||
case "notreserved":
|
||||
@ -181,6 +187,14 @@ func validateReservedKeywords(fl validator.FieldLevel) bool {
|
||||
return !ok
|
||||
}
|
||||
|
||||
func validateAlphaNumDash(fl validator.FieldLevel) bool {
|
||||
return regexp.MustCompile(`^[a-zA-Z0-9-]+$`).MatchString(fl.Field().String())
|
||||
}
|
||||
|
||||
func validateAlphaNumDashOrEmpty(fl validator.FieldLevel) bool {
|
||||
return regexp.MustCompile(`^$|^[a-zA-Z0-9-]+$`).MatchString(fl.Field().String())
|
||||
}
|
||||
|
||||
func getPage(ctx echo.Context) int {
|
||||
page := ctx.QueryParam("page")
|
||||
if page == "" {
|
||||
|
Reference in New Issue
Block a user