Make file upload limits configurable (#1079)

This commit is contained in:
InfiniteTF
2021-01-29 10:27:02 +01:00
committed by GitHub
parent df8675c2e7
commit 89fcd6d775
6 changed files with 29 additions and 4 deletions

View File

@@ -134,12 +134,13 @@ func Start() {
return true
},
})
maxUploadSize := handler.UploadMaxSize(config.GetMaxUploadSize())
txnManager := manager.GetInstance().TxnManager
resolver := &Resolver{
txnManager: txnManager,
}
gqlHandler := handler.GraphQL(models.NewExecutableSchema(models.Config{Resolvers: resolver}), recoverFunc, websocketUpgrader)
gqlHandler := handler.GraphQL(models.NewExecutableSchema(models.Config{Resolvers: resolver}), recoverFunc, websocketUpgrader, maxUploadSize)
r.Handle("/graphql", gqlHandler)
r.Handle("/playground", handler.Playground("GraphQL playground", "/graphql"))

View File

@@ -120,6 +120,9 @@ const LogOut = "logOut"
const LogLevel = "logLevel"
const LogAccess = "logAccess"
// File upload options
const MaxUploadSize = "max_upload_size"
func Set(key string, value interface{}) {
viper.Set(key, value)
}
@@ -579,6 +582,15 @@ func GetLogAccess() bool {
return ret
}
// Max allowed graphql upload size in megabytes
func GetMaxUploadSize() int64 {
ret := int64(1024)
if viper.IsSet(MaxUploadSize) {
ret = viper.GetInt64(MaxUploadSize)
}
return ret << 20
}
func IsValid() bool {
setPaths := viper.IsSet(Stash) && viper.IsSet(Cache) && viper.IsSet(Generated) && viper.IsSet(Metadata)

View File

@@ -172,17 +172,21 @@ func (t *ImportTask) unzipFile() error {
if err != nil {
return err
}
defer o.Close()
i, err := f.Open()
if err != nil {
o.Close()
return err
}
defer i.Close()
if _, err := io.Copy(o, i); err != nil {
o.Close()
i.Close()
return err
}
o.Close()
i.Close()
}
return nil

View File

@@ -14,4 +14,4 @@ func NullInt64(v int64) sql.NullInt64 {
Int64: v,
Valid: true,
}
}
}

View File

@@ -7,6 +7,7 @@
* Allow configuration of visible navbar items.
### 🎨 Improvements
* Added configuration option for import file size limit and increased default to 1GB.
* Add dry-run option for Clean task.
* Refresh UI when changing custom CSS options.
* Add batch deleting of performers, tags, studios, and movies.

View File

@@ -103,3 +103,10 @@ Stash saves login credentials in the config.yml file. You must reset both login
* Delete the `login` and `password` lines from the file and save
Stash authentication should now be reset with no authentication credentials.
## Advanced configuration options
These options are typically not exposed in the UI and must be changed manually in the `config.yml` file.
| Field | Remarks |
|-------|---------|
| `max_upload_size` | Maximum file upload size for import files. Defaults to 1GB. |