replace stashBox validation (#5187)

This commit is contained in:
DirtyRacer1337 2024-09-05 09:59:05 +07:00 committed by GitHub
parent 879c20efc7
commit 601a16b5cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ package config
import (
"fmt"
"net/url"
"os"
"path/filepath"
"reflect"
@ -1097,7 +1098,10 @@ func (i *Config) ValidateCredentials(username string, password string) bool {
return username == authUser && err == nil
}
var stashBoxRe = regexp.MustCompile("^http.*graphql$")
func stashBoxValidate(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != "" && strings.HasSuffix(u.Path, "/graphql")
}
type StashBoxInput struct {
Endpoint string `json:"endpoint"`
@ -1118,7 +1122,7 @@ func (i *Config) ValidateStashBoxes(boxes []*StashBoxInput) error {
return &StashBoxError{msg: "endpoint cannot be blank"}
}
if !stashBoxRe.Match([]byte(box.Endpoint)) {
if !stashBoxValidate(box.Endpoint) {
return &StashBoxError{msg: "endpoint is invalid"}
}