1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-29 08:22:11 +02:00
imgproxy/presets.go

57 lines
1.0 KiB
Go
Raw Normal View History

2018-09-07 19:41:06 +02:00
package main
import (
2018-11-06 13:19:34 +02:00
"fmt"
"strings"
)
2018-09-07 19:41:06 +02:00
type presets map[string]urlOptions
2018-11-06 13:19:34 +02:00
func parsePreset(p presets, presetStr string) error {
2018-09-07 19:41:06 +02:00
presetStr = strings.Trim(presetStr, " ")
if len(presetStr) == 0 || strings.HasPrefix(presetStr, "#") {
2018-11-06 13:19:34 +02:00
return nil
2018-09-07 19:41:06 +02:00
}
parts := strings.Split(presetStr, "=")
if len(parts) != 2 {
2018-11-06 13:19:34 +02:00
return fmt.Errorf("Invalid preset string: %s", presetStr)
2018-09-07 19:41:06 +02:00
}
name := strings.Trim(parts[0], " ")
if len(name) == 0 {
2018-11-06 13:19:34 +02:00
return fmt.Errorf("Empty preset name: %s", presetStr)
2018-09-07 19:41:06 +02:00
}
value := strings.Trim(parts[1], " ")
if len(value) == 0 {
2018-11-06 13:19:34 +02:00
return fmt.Errorf("Empty preset value: %s", presetStr)
2018-09-07 19:41:06 +02:00
}
optsStr := strings.Split(value, "/")
opts, rest := parseURLOptions(optsStr)
if len(rest) > 0 {
2018-11-06 13:19:34 +02:00
return fmt.Errorf("Invalid preset value: %s", presetStr)
}
p[name] = opts
2018-11-06 13:19:34 +02:00
return nil
}
2018-11-06 13:19:34 +02:00
func checkPresets(p presets) error {
var po processingOptions
for name, opts := range p {
if err := applyProcessingOptions(&po, opts); err != nil {
2018-11-06 13:19:34 +02:00
return fmt.Errorf("Error in preset `%s`: %s", name, err)
}
2018-09-07 19:41:06 +02:00
}
2018-11-06 13:19:34 +02:00
return nil
2018-09-07 19:41:06 +02:00
}