Add UploadedImagesDir config setting
This commit is contained in:
parent
b738115b72
commit
dfe242b0cd
|
|
@ -66,6 +66,7 @@ defaultuser: # on database creation, gotify creates an admin user
|
|||
name: admin # the username of the default user
|
||||
pass: admin # the password of the default user
|
||||
passstrength: 10 # the bcrypt password strength (higher = better but also slower)
|
||||
uploadedimagesdir: images # the directory for storing uploaded images
|
||||
```
|
||||
|
||||
### Environment
|
||||
|
|
@ -86,6 +87,7 @@ GOTIFY_DATABASE_CONNECTION=gotify.db
|
|||
GOTIFY_DEFAULTUSER_NAME=admin
|
||||
GOTIFY_DEFAULTUSER_PASS=admin
|
||||
GOTIFY_PASSSTRENGTH=10
|
||||
GOTIFY_UPLOADEDIMAGESDIR=images
|
||||
```
|
||||
|
||||
### Database
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package config
|
||||
|
||||
import "github.com/jinzhu/configor"
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jinzhu/configor"
|
||||
)
|
||||
|
||||
// Configuration is stuff that can be configured externally per env variables or config file (config.yml).
|
||||
type Configuration struct {
|
||||
|
|
@ -28,12 +33,20 @@ type Configuration struct {
|
|||
Name string `default:"admin"`
|
||||
Pass string `default:"admin"`
|
||||
}
|
||||
PassStrength int `default:"10"`
|
||||
PassStrength int `default:"10"`
|
||||
UploadedImagesDir string `default:"images"`
|
||||
}
|
||||
|
||||
// Get returns the configuration extracted from env variables or config file.
|
||||
func Get() *Configuration {
|
||||
conf := new(Configuration)
|
||||
configor.New(&configor.Config{ENVPrefix: "GOTIFY"}).Load(conf, "config.yml", "/etc/gotify/config.yml")
|
||||
addTrailingSlashToPaths(conf)
|
||||
return conf
|
||||
}
|
||||
|
||||
func addTrailingSlashToPaths(conf *Configuration) {
|
||||
if !strings.HasSuffix(conf.UploadedImagesDir, "/") && !strings.HasSuffix(conf.UploadedImagesDir, "\\") {
|
||||
conf.UploadedImagesDir = conf.UploadedImagesDir + string(filepath.Separator)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
@ -18,6 +20,20 @@ func TestConfigEnv(t *testing.T) {
|
|||
os.Unsetenv("GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS")
|
||||
}
|
||||
|
||||
func TestAddSlash(t *testing.T) {
|
||||
os.Setenv("GOTIFY_UPLOADEDIMAGESDIR", "../data/images")
|
||||
conf := Get()
|
||||
assert.Equal(t, "../data/images"+string(filepath.Separator), conf.UploadedImagesDir)
|
||||
os.Unsetenv("GOTIFY_UPLOADEDIMAGESDIR")
|
||||
}
|
||||
|
||||
func TestNotAddSlash(t *testing.T) {
|
||||
os.Setenv("GOTIFY_UPLOADEDIMAGESDIR", "../data/")
|
||||
conf := Get()
|
||||
assert.Equal(t, "../data/", conf.UploadedImagesDir)
|
||||
os.Unsetenv("GOTIFY_UPLOADEDIMAGESDIR")
|
||||
}
|
||||
|
||||
func TestConfigFile(t *testing.T) {
|
||||
file, err := os.Create("config.yml")
|
||||
defer func() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue