diff options
author | Ollie Phillips <7113347+olliephillips@users.noreply.github.com> | 2019-08-01 16:48:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-01 16:48:22 +0100 |
commit | f0472b990d7022e2022538d54286bd11ecfaa912 (patch) | |
tree | 7928413f9d392e0fb2b683225dc6a7bcc5804ef6 /system/admin/filesystem.go | |
parent | 3ef2dc0da5d39686da48ac90e8a8a2c6b861e549 (diff) | |
parent | 4beb78e420595eea405566741490b2aa2f5e1854 (diff) |
Merge pull request #311 from ponzu-cms/ponzu-dev
Merging ponzu-dev to master as v0.11.0
Diffstat (limited to 'system/admin/filesystem.go')
-rw-r--r-- | system/admin/filesystem.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/system/admin/filesystem.go b/system/admin/filesystem.go index 77c721e..758966b 100644 --- a/system/admin/filesystem.go +++ b/system/admin/filesystem.go @@ -1,10 +1,41 @@ package admin import ( + "encoding/json" "net/http" "os" + "path/filepath" + "strings" + + "github.com/ponzu-cms/ponzu/system/db" + "github.com/ponzu-cms/ponzu/system/item" ) +func deleteUploadFromDisk(target string) error { + // get data on file + data, err := db.Upload(target) + if err != nil { + return err + } + + // unmarshal data + upload := item.FileUpload{} + if err = json.Unmarshal(data, &upload); err != nil { + return err + } + + // split and rebuild path in OS friendly way + // use path to delete the physical file from disk + pathSplit := strings.Split(strings.TrimPrefix(upload.Path, "/api/"), "/") + pathJoin := filepath.Join(pathSplit...) + err = os.Remove(pathJoin) + if err != nil { + return err + } + + return nil +} + func restrict(dir http.Dir) justFilesFilesystem { return justFilesFilesystem{dir} } |