mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-18 16:31:44 +02:00
Add IMGPROXY_ARGUMENTS_SEPARATOR and IMGPROXY_PRESETS_SEPARATOR configs
This commit is contained in:
parent
6e4967a278
commit
23baf1cae0
@ -5,6 +5,8 @@
|
||||
- Add [IMGPROXY_S3_ASSUME_ROLE_EXTERNAL_ID](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_S3_ASSUME_ROLE_EXTERNAL_ID) config.
|
||||
- Add [IMGPROXY_WRITE_RESPONSE_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_WRITE_RESPONSE_TIMEOUT) config.
|
||||
- Add [IMGPROXY_REPORT_IO_ERRORS](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_REPORT_IO_ERRORS) config.
|
||||
- Add [IMGPROXY_ARGUMENTS_SEPARATOR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ARGUMENTS_SEPARATOR) config.
|
||||
- Add [IMGPROXY_PRESETS_SEPARATOR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_PRESETS_SEPARATOR) config.
|
||||
- (pro) Add [colorize](https://docs.imgproxy.net/latest/usage/processing#colorize) processing option.
|
||||
|
||||
### Changed
|
||||
|
@ -198,6 +198,8 @@ var (
|
||||
BufferPoolCalibrationThreshold int
|
||||
|
||||
HealthCheckPath string
|
||||
|
||||
ArgumentsSeparator string
|
||||
)
|
||||
|
||||
var (
|
||||
@ -392,6 +394,8 @@ func Reset() {
|
||||
BufferPoolCalibrationThreshold = 1024
|
||||
|
||||
HealthCheckPath = ""
|
||||
|
||||
ArgumentsSeparator = ":"
|
||||
}
|
||||
|
||||
func Configure() error {
|
||||
@ -489,6 +493,8 @@ func Configure() error {
|
||||
|
||||
configurators.URLPath(&HealthCheckPath, "IMGPROXY_HEALTH_CHECK_PATH")
|
||||
|
||||
configurators.String(&ArgumentsSeparator, "IMGPROXY_ARGUMENTS_SEPARATOR")
|
||||
|
||||
if err := configurators.ImageTypes(&PreferredFormats, "IMGPROXY_PREFERRED_FORMATS"); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -566,7 +572,9 @@ func Configure() error {
|
||||
return err
|
||||
}
|
||||
|
||||
configurators.StringSlice(&Presets, "IMGPROXY_PRESETS")
|
||||
presetsSep := ","
|
||||
configurators.String(&presetsSep, "IMGPROXY_PRESETS_SEPARATOR")
|
||||
configurators.StringSliceSep(&Presets, "IMGPROXY_PRESETS", presetsSep)
|
||||
if err := configurators.StringSliceFile(&Presets, presetsPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ func String(s *string, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func StringSlice(s *[]string, name string) {
|
||||
func StringSliceSep(s *[]string, name, sep string) {
|
||||
if env := os.Getenv(name); len(env) > 0 {
|
||||
parts := strings.Split(env, ",")
|
||||
parts := strings.Split(env, sep)
|
||||
|
||||
for i, p := range parts {
|
||||
parts[i] = strings.TrimSpace(p)
|
||||
@ -57,6 +57,10 @@ func StringSlice(s *[]string, name string) {
|
||||
*s = []string{}
|
||||
}
|
||||
|
||||
func StringSlice(s *[]string, name string) {
|
||||
StringSliceSep(s, name, ",")
|
||||
}
|
||||
|
||||
func StringSliceFile(s *[]string, filepath string) error {
|
||||
if len(filepath) == 0 {
|
||||
return nil
|
||||
|
@ -1173,7 +1173,7 @@ func parsePathPresets(parts []string, headers http.Header) (*ProcessingOptions,
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
presets := strings.Split(parts[0], ":")
|
||||
presets := strings.Split(parts[0], config.ArgumentsSeparator)
|
||||
urlParts := parts[1:]
|
||||
|
||||
if err = applyPresetOption(po, presets); err != nil {
|
||||
|
@ -138,6 +138,19 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseWithArgumentsSeparator() {
|
||||
config.ArgumentsSeparator = ","
|
||||
|
||||
path := "/size,100,100,1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(100, po.Width)
|
||||
s.Require().Equal(100, po.Height)
|
||||
s.Require().True(po.Enlarge)
|
||||
}
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParseURLAllowedSource() {
|
||||
// config.AllowedSources = []string{"local://", "http://images.dev/"}
|
||||
|
||||
@ -546,25 +559,6 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
||||
s.Require().InDelta(1.0, po.Dpr, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
urlOption{Name: "blur", Args: []string{"0.2"}},
|
||||
}
|
||||
presets["test2"] = urlOptions{
|
||||
urlOption{Name: "quality", Args: []string{"50"}},
|
||||
}
|
||||
|
||||
path := "/test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
||||
path := "/skp:jpg:png/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
@ -599,6 +593,25 @@ func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
|
||||
s.Require().Equal(errExpiredURL.Error(), err.Error())
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
urlOption{Name: "blur", Args: []string{"0.2"}},
|
||||
}
|
||||
presets["test2"] = urlOptions{
|
||||
urlOption{Name: "quality", Args: []string{"50"}},
|
||||
}
|
||||
|
||||
path := "/test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
|
@ -1,6 +1,10 @@
|
||||
package options
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
)
|
||||
|
||||
type urlOption struct {
|
||||
Name string
|
||||
@ -14,7 +18,7 @@ func parseURLOptions(opts []string) (urlOptions, []string) {
|
||||
urlStart := len(opts) + 1
|
||||
|
||||
for i, opt := range opts {
|
||||
args := strings.Split(opt, ":")
|
||||
args := strings.Split(opt, config.ArgumentsSeparator)
|
||||
|
||||
if len(args) == 1 {
|
||||
urlStart = i
|
||||
|
Loading…
Reference in New Issue
Block a user