mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-24 22:25:15 +00:00
fix(attachments): extend upload file size to form data (#1577)
Resolves https://github.com/go-vikunja/vikunja/issues/1494
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -213,6 +214,8 @@ const (
|
||||
PluginsDir Key = `plugins.dir`
|
||||
)
|
||||
|
||||
var maxFileSizeInBytes uint64
|
||||
|
||||
// GetString returns a string config value
|
||||
func (k Key) GetString() string {
|
||||
return viper.GetString(string(k))
|
||||
@@ -622,6 +625,11 @@ func InitConfig() {
|
||||
|
||||
publicURL := strings.TrimSuffix(ServicePublicURL.GetString(), "/")
|
||||
CorsOrigins.Set(append(CorsOrigins.GetStringSlice(), publicURL))
|
||||
|
||||
err = SetMaxFileSizeMBytesFromString(FilesMaxSize.GetString())
|
||||
if err != nil {
|
||||
log.Fatalf("Could not parse files.maxsize: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func random(length int) (string, error) {
|
||||
@@ -632,3 +640,21 @@ func random(length int) (string, error) {
|
||||
|
||||
return fmt.Sprintf("%X", b), nil
|
||||
}
|
||||
|
||||
func SetMaxFileSizeMBytesFromString(size string) error {
|
||||
var maxSize datasize.ByteSize
|
||||
err := maxSize.UnmarshalText([]byte(size))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maxFileSizeInBytes = uint64(maxSize.MBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetMaxFileSizeInMBytes() uint64 {
|
||||
if maxFileSizeInBytes == 0 {
|
||||
return 20
|
||||
}
|
||||
return maxFileSizeInBytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user