fix(attachments): extend upload file size to form data (#1577)

Resolves https://github.com/go-vikunja/vikunja/issues/1494
This commit is contained in:
kolaente
2025-10-01 00:23:07 +02:00
committed by GitHub
parent 31c1f98270
commit ec89b08fd5
9 changed files with 203 additions and 21 deletions

View File

@@ -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
}