mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-12 11:46:10 +02:00
parent
27dbed077f
commit
098f6b9fc9
@ -480,6 +480,17 @@ It's highly recommended to prefer `cachebuster` option over URL query string bec
|
||||
|
||||
Default: empty
|
||||
|
||||
### Expires
|
||||
|
||||
```
|
||||
expires:%timestamp
|
||||
exp:%timestamp
|
||||
```
|
||||
|
||||
When set, imgproxy will check provided unix timestamp and return 404 when expired.
|
||||
|
||||
Default: empty
|
||||
|
||||
### Strip Metadata
|
||||
|
||||
```
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v2/structdiff"
|
||||
)
|
||||
@ -169,6 +170,7 @@ const (
|
||||
msgForbidden = "Forbidden"
|
||||
msgInvalidURL = "Invalid URL"
|
||||
msgInvalidSource = "Invalid Source"
|
||||
msgExpiredURL = "Expired URL"
|
||||
)
|
||||
|
||||
func (gt gravityType) String() string {
|
||||
@ -888,6 +890,23 @@ func applyFilenameOption(po *processingOptions, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyExpiresOption(po *processingOptions, args []string) error {
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("Invalid expires arguments: %v", args)
|
||||
}
|
||||
|
||||
timestamp, err := strconv.ParseInt(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid expires argument: %v", args[0])
|
||||
}
|
||||
|
||||
if timestamp > 0 && timestamp < time.Now().Unix() {
|
||||
return errors.New(msgExpiredURL)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyStripMetadataOption(po *processingOptions, args []string) error {
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("Invalid strip metadata arguments: %v", args)
|
||||
@ -972,6 +991,8 @@ func applyProcessingOption(po *processingOptions, name string, args []string) er
|
||||
return applyAutoRotateOption(po, args)
|
||||
case "filename", "fn":
|
||||
return applyFilenameOption(po, args)
|
||||
case "expires", "exp":
|
||||
return applyExpiresOption(po, args)
|
||||
}
|
||||
|
||||
return fmt.Errorf("Unknown processing option: %s", name)
|
||||
|
@ -568,6 +568,21 @@ func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
assert.Equal(s.T(), 50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseExpires() {
|
||||
req := s.getRequest("/unsafe/exp:32503669200/plain/http://images.dev/lorem/ipsum.jpg")
|
||||
_, err := parsePath(context.Background(), req)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
|
||||
req := s.getRequest("/unsafe/exp:1609448400/plain/http://images.dev/lorem/ipsum.jpg")
|
||||
_, err := parsePath(context.Background(), req)
|
||||
|
||||
require.Error(s.T(), err)
|
||||
assert.Equal(s.T(), msgExpiredURL, err.Error())
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||
conf.OnlyPresets = true
|
||||
conf.Presets["test1"] = urlOptions{
|
||||
|
Loading…
x
Reference in New Issue
Block a user