summaryrefslogtreecommitdiff
path: root/system/admin
diff options
context:
space:
mode:
Diffstat (limited to 'system/admin')
-rw-r--r--system/admin/server.go12
-rw-r--r--system/admin/upload/upload.go11
2 files changed, 8 insertions, 15 deletions
diff --git a/system/admin/server.go b/system/admin/server.go
index 9f28a0d..b912d4d 100644
--- a/system/admin/server.go
+++ b/system/admin/server.go
@@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
+ "github.com/ponzu-cms/ponzu/system/cfg"
+
"github.com/ponzu-cms/ponzu/system"
"github.com/ponzu-cms/ponzu/system/admin/user"
"github.com/ponzu-cms/ponzu/system/api"
@@ -46,18 +48,14 @@ func Run() {
http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler))
http.HandleFunc("/admin/edit/upload/delete", user.Auth(deleteUploadHandler))
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatalln("Couldn't find current directory for file server.")
- }
+ staticDir := cfg.AdminStaticDir()
- staticDir := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system")
- http.Handle("/admin/static/", db.CacheControl(http.FileServer(restrict(http.Dir(staticDir)))))
+ http.Handle("/admin/static/", db.CacheControl(http.StripPrefix("/admin/static", http.FileServer(restrict(http.Dir(staticDir))))))
// API path needs to be registered within server package so that it is handled
// even if the API server is not running. Otherwise, images/files uploaded
// through the editor will not load within the admin system.
- uploadsDir := filepath.Join(pwd, "uploads")
+ uploadsDir := cfg.UploadDir()
http.Handle("/api/uploads/", api.Record(api.CORS(db.CacheControl(http.StripPrefix("/api/uploads/", http.FileServer(restrict(http.Dir(uploadsDir))))))))
// Database & uploads backup via HTTP route registered with Basic Auth middleware.
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