diff options
author | Steve Manuel <nilslice@gmail.com> | 2020-01-01 17:14:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-01 17:14:32 -0700 |
commit | 9bc41b703131aa42ca64265ab6fdeadc37841e66 (patch) | |
tree | 138e6b7d6f8bd5c879eff61ce85df95506546003 /system/admin/upload | |
parent | 45730ba5b4de56fed27f79f8c822bb59d41f7a38 (diff) | |
parent | 6ee81caea4649d3fc3bb6b5bde0628cb91c8e6f5 (diff) |
Merge pull request #333 from mangelajo/env-vars-for-dirs
Allow data directories outside pwd
Diffstat (limited to 'system/admin/upload')
-rw-r--r-- | system/admin/upload/upload.go | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/system/admin/upload/upload.go b/system/admin/upload/upload.go index fd29796..a5a2d1c 100644 --- a/system/admin/upload/upload.go +++ b/system/admin/upload/upload.go @@ -14,6 +14,8 @@ import ( "strconv" "time" + "github.com/ponzu-cms/ponzu/system/cfg" + "github.com/ponzu-cms/ponzu/system/db" "github.com/ponzu-cms/ponzu/system/item" ) @@ -41,12 +43,6 @@ func StoreFiles(req *http.Request) (map[string]string, error) { req.Form.Set("timestamp", ts) // get or create upload directory to save files from request - pwd, err := os.Getwd() - if err != nil { - err := fmt.Errorf("Failed to locate current directory: %s", err) - return nil, err - } - i, err := strconv.ParseInt(ts, 10, 64) if err != nil { return nil, err @@ -56,8 +52,7 @@ func StoreFiles(req *http.Request) (map[string]string, error) { urlPathPrefix := "api" uploadDirName := "uploads" - - uploadDir := filepath.Join(pwd, uploadDirName, fmt.Sprintf("%d", tm.Year()), fmt.Sprintf("%02d", tm.Month())) + uploadDir := filepath.Join(cfg.UploadDir(), fmt.Sprintf("%d", tm.Year()), fmt.Sprintf("%02d", tm.Month())) err = os.MkdirAll(uploadDir, os.ModeDir|os.ModePerm) if err != nil { return nil, err |