mirror of https://gitlab.com/ngerakines/tavern.git
Added flag to set max file size limit for remote download. Closes #20
This commit is contained in:
parent
7a0dc3ee03
commit
4bbd3e54e7
|
@ -55,13 +55,13 @@ func (a Agent) HandleImage(ctx context.Context, location string) (storage.ImageA
|
|||
return storage.ImageAsset{}, err
|
||||
}
|
||||
|
||||
lsr := io.LimitReader(sourceReader, 5000001) // 5 megs
|
||||
lsr := io.LimitReader(sourceReader, a.AssetStorageConfig.MaxFileSize+1) // 5 megs
|
||||
|
||||
written, err := io.Copy(w, lsr)
|
||||
if err != nil {
|
||||
return storage.ImageAsset{}, err
|
||||
}
|
||||
if written > 5000000 {
|
||||
if written > a.AssetStorageConfig.MaxFileSize {
|
||||
return storage.ImageAsset{}, fmt.Errorf("file size limit of 5 megabytes reached")
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,13 @@ var AssetStorageRemoteDenyFlag = cli.StringSliceFlag{
|
|||
EnvVars: []string{"ASSET_STORAGE_REMOTE_DENY"},
|
||||
}
|
||||
|
||||
var AssetStorageRemoteMaxFlag = cli.Int64Flag{
|
||||
Name: "asset-storage-max",
|
||||
Usage: "Asset storage remote max file size.",
|
||||
Value: 5000000,
|
||||
EnvVars: []string{"ASSET_STORAGE_REMOTE_MAX"},
|
||||
}
|
||||
|
||||
type AssetStore interface {
|
||||
Close() error
|
||||
Create(ctx context.Context, location string, reader io.Reader) (string, error)
|
||||
|
@ -47,6 +54,7 @@ type AssetStore interface {
|
|||
type AssetStorageConfig struct {
|
||||
Type string
|
||||
FileBasePath string
|
||||
MaxFileSize int64
|
||||
|
||||
AllowDomains []common.AllowDenyMatcher
|
||||
DenyDomains []common.AllowDenyMatcher
|
||||
|
@ -69,6 +77,7 @@ func AssetStorage(c *cli.Context) AssetStorageConfig {
|
|||
return AssetStorageConfig{
|
||||
Type: c.String("asset-storage"),
|
||||
FileBasePath: c.String("asset-storage-file-base"),
|
||||
MaxFileSize: c.Int64("asset-storage-max"),
|
||||
|
||||
AllowDomains: allowDomains,
|
||||
DenyDomains: denyDomains,
|
||||
|
|
|
@ -57,6 +57,7 @@ var Command = cli.Command{
|
|||
&config.AssetStorageFileBaseFlag,
|
||||
&config.AssetStorageRemoteAllowFlag,
|
||||
&config.AssetStorageRemoteDenyFlag,
|
||||
&config.AssetStorageRemoteMaxFlag,
|
||||
},
|
||||
Action: serverCommandAction,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue