Skip to content

🎥 Make videos programmatically with React

update validation rules

Alex Fernandezfaeb4aedb5a6
diff --git a/packages/goclient-example/main.go b/packages/goclient-example/main.go
index ad08e549f3..003409678b 100644
--- a/packages/goclient-example/main.go
+++ b/packages/goclient-example/main.go
@@ -19,8 +19,7 @@ func msgForTag(fe validator.FieldError) string {
switch fe.Tag() {
case "required":
return "This field is required"
- case "email":
- return "Invalid email"
+
}
return fe.Error() // default error
}
@@ -84,11 +83,12 @@ func main() {
validationOut := make([]ValidationError, len(error.(validator.ValidationErrors)))
for i, fieldError := range error.(validator.ValidationErrors) {
+ //println(fieldError.Value().(int))
validationOut[i] = ValidationError{fieldError.Field(), msgForTag(fieldError)}
}
for _, apiError := range validationOut {
- fmt.Printf("%s: %s\n", apiError.Param, apiError.Message)
+ fmt.Printf("%s: %s\n", apiError.Field, apiError.Message)
}
return
diff --git a/packages/goclient/internalops.go b/packages/goclient/internalops.go
index c652873b9b..6c13bf4203 100644
--- a/packages/goclient/internalops.go
+++ b/packages/goclient/internalops.go
@@ -14,7 +14,7 @@ func constructInternals(options RemotionOptions) (*internalOptions, error) {
log.Fatal("Error in serializing input props", serializeError)
}
validate := validator.New()
-
+ validate.RegisterValidation("privacyTypeValidator", privacyTypeValidator)
validationErrors := validate.Struct(options)
if validationErrors != nil {
@@ -27,7 +27,6 @@ func constructInternals(options RemotionOptions) (*internalOptions, error) {
Composition: options.Composition,
Region: options.Region,
Type: options.Type,
- Codec: options.Codec,
Version: options.Version,
ImageFormat: options.ImageFormat,
Crf: options.Crf,
@@ -57,5 +56,9 @@ func constructInternals(options RemotionOptions) (*internalOptions, error) {
ForceBucketName: options.ForceBucketName,
}
+ if &options.Codec == nil {
+ internalParams.Codec = "h264"
+ }
+
return internalParams, nil
}
diff --git a/packages/goclient/models.go b/packages/goclient/models.go
index 1a589890a5..95295b37e6 100644
--- a/packages/goclient/models.go
+++ b/packages/goclient/models.go
@@ -1,12 +1,25 @@
package goclient
+type PrivacyType string
+
+const (
+ Public PrivacyType = "public"
+ Private PrivacyType = "private"
+ NoACL PrivacyType = "no-acl"
+)
+
+/*
+*
+
+ TODO Validation rules
+*/
type RemotionOptions struct {
ServeUrl string `json:"serveUrl" validate:"required"`
FunctionName string `json:"functionName" validate:"required"`
Region string `json:"region" validate:"required"`
InputProps interface{} `json:"inputProps"`
Composition string `json:"composition" validate:"required"`
- Type string `json:"type"`
+ Type string `json:"type" validate:"required"`
Codec string `json:"codec"`
Version string `json:"version"`
ImageFormat string `json:"imageFormat"`
@@ -14,7 +27,7 @@ type RemotionOptions struct {
EnvVariables []interface{} `json:"envVariables"`
Quality int `json:"quality" validate:"required,min=1,max=100"`
MaxRetries int `json:"maxRetries"`
- Privacy string `json:"privacy"`
+ Privacy PrivacyType `json:"privacy" validate:"required,privacyTypeValidator"`
LogLevel string `json:"logLevel"`
FrameRange interface{} `json:"frameRange"`
OutName interface{} `json:"outName"`
@@ -51,7 +64,7 @@ type internalOptions struct {
EnvVariables []interface{}
Quality int
MaxRetries int `json:"maxRetries"`
- Privacy string `json:"privacy"`
+ Privacy PrivacyType `json:"privacy"`
LogLevel string `json:"logLevel"`
FrameRange interface{} `json:"frameRange"`
OutName interface{} `json:"outName"`
diff --git a/packages/goclient/validation.go b/packages/goclient/validation.go
index 0948e17a8b..e3173b4170 100644
--- a/packages/goclient/validation.go
+++ b/packages/goclient/validation.go
@@ -13,3 +13,14 @@ func qualityRange(fl validator.FieldLevel) bool {
}
return quality >= 1 && quality <= 100
}
+
+func privacyTypeValidator(fl validator.FieldLevel) bool {
+ value, ok := fl.Field().Interface().(PrivacyType)
+ if ok {
+ switch value {
+ case Public, Private, NoACL:
+ return true
+ }
+ }
+ return false
+}