mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-27 12:07:59 +02:00
Add IMGPROXY_ARGUMENTS_SEPARATOR and IMGPROXY_PRESETS_SEPARATOR configs
This commit is contained in:
@@ -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_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_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_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.
|
- (pro) Add [colorize](https://docs.imgproxy.net/latest/usage/processing#colorize) processing option.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@@ -198,6 +198,8 @@ var (
|
|||||||
BufferPoolCalibrationThreshold int
|
BufferPoolCalibrationThreshold int
|
||||||
|
|
||||||
HealthCheckPath string
|
HealthCheckPath string
|
||||||
|
|
||||||
|
ArgumentsSeparator string
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -392,6 +394,8 @@ func Reset() {
|
|||||||
BufferPoolCalibrationThreshold = 1024
|
BufferPoolCalibrationThreshold = 1024
|
||||||
|
|
||||||
HealthCheckPath = ""
|
HealthCheckPath = ""
|
||||||
|
|
||||||
|
ArgumentsSeparator = ":"
|
||||||
}
|
}
|
||||||
|
|
||||||
func Configure() error {
|
func Configure() error {
|
||||||
@@ -489,6 +493,8 @@ func Configure() error {
|
|||||||
|
|
||||||
configurators.URLPath(&HealthCheckPath, "IMGPROXY_HEALTH_CHECK_PATH")
|
configurators.URLPath(&HealthCheckPath, "IMGPROXY_HEALTH_CHECK_PATH")
|
||||||
|
|
||||||
|
configurators.String(&ArgumentsSeparator, "IMGPROXY_ARGUMENTS_SEPARATOR")
|
||||||
|
|
||||||
if err := configurators.ImageTypes(&PreferredFormats, "IMGPROXY_PREFERRED_FORMATS"); err != nil {
|
if err := configurators.ImageTypes(&PreferredFormats, "IMGPROXY_PREFERRED_FORMATS"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -566,7 +572,9 @@ func Configure() error {
|
|||||||
return err
|
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 {
|
if err := configurators.StringSliceFile(&Presets, presetsPath); err != nil {
|
||||||
return err
|
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 {
|
if env := os.Getenv(name); len(env) > 0 {
|
||||||
parts := strings.Split(env, ",")
|
parts := strings.Split(env, sep)
|
||||||
|
|
||||||
for i, p := range parts {
|
for i, p := range parts {
|
||||||
parts[i] = strings.TrimSpace(p)
|
parts[i] = strings.TrimSpace(p)
|
||||||
@@ -57,6 +57,10 @@ func StringSlice(s *[]string, name string) {
|
|||||||
*s = []string{}
|
*s = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StringSlice(s *[]string, name string) {
|
||||||
|
StringSliceSep(s, name, ",")
|
||||||
|
}
|
||||||
|
|
||||||
func StringSliceFile(s *[]string, filepath string) error {
|
func StringSliceFile(s *[]string, filepath string) error {
|
||||||
if len(filepath) == 0 {
|
if len(filepath) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@@ -1173,7 +1173,7 @@ func parsePathPresets(parts []string, headers http.Header) (*ProcessingOptions,
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
presets := strings.Split(parts[0], ":")
|
presets := strings.Split(parts[0], config.ArgumentsSeparator)
|
||||||
urlParts := parts[1:]
|
urlParts := parts[1:]
|
||||||
|
|
||||||
if err = applyPresetOption(po, presets); err != nil {
|
if err = applyPresetOption(po, presets); err != nil {
|
||||||
|
@@ -138,6 +138,19 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
|||||||
s.Require().Equal(imagetype.PNG, po.Format)
|
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() {
|
// func (s *ProcessingOptionsTestSuite) TestParseURLAllowedSource() {
|
||||||
// config.AllowedSources = []string{"local://", "http://images.dev/"}
|
// config.AllowedSources = []string{"local://", "http://images.dev/"}
|
||||||
|
|
||||||
@@ -546,25 +559,6 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
|||||||
s.Require().InDelta(1.0, po.Dpr, 0.0001)
|
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() {
|
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
||||||
path := "/skp:jpg:png/plain/http://images.dev/lorem/ipsum.jpg"
|
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())
|
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() {
|
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||||
config.OnlyPresets = true
|
config.OnlyPresets = true
|
||||||
presets["test1"] = urlOptions{
|
presets["test1"] = urlOptions{
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
package options
|
package options
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/imgproxy/imgproxy/v3/config"
|
||||||
|
)
|
||||||
|
|
||||||
type urlOption struct {
|
type urlOption struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -14,7 +18,7 @@ func parseURLOptions(opts []string) (urlOptions, []string) {
|
|||||||
urlStart := len(opts) + 1
|
urlStart := len(opts) + 1
|
||||||
|
|
||||||
for i, opt := range opts {
|
for i, opt := range opts {
|
||||||
args := strings.Split(opt, ":")
|
args := strings.Split(opt, config.ArgumentsSeparator)
|
||||||
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
urlStart = i
|
urlStart = i
|
||||||
|
Reference in New Issue
Block a user