summaryrefslogtreecommitdiff
path: root/system/admin/filesystem.go
diff options
context:
space:
mode:
authorOllie Phillips <oliver@eantics.co.uk>2019-03-25 22:51:15 +0000
committerOllie Phillips <oliver@eantics.co.uk>2019-03-25 22:51:15 +0000
commit9ea64498a0752d261e45f15e45843ef09c506cf9 (patch)
treeaa9b1ca113a5f73abd8b9aabb19174ad68e8a0f5 /system/admin/filesystem.go
parent20da628b140cd90b5937c412a8fa6670389bff38 (diff)
delete physical upload from disk
Diffstat (limited to 'system/admin/filesystem.go')
-rw-r--r--system/admin/filesystem.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/system/admin/filesystem.go b/system/admin/filesystem.go
index 77c721e..21e9740 100644
--- a/system/admin/filesystem.go
+++ b/system/admin/filesystem.go
@@ -1,10 +1,38 @@
package admin
import (
+ "encoding/json"
"net/http"
"os"
+ "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
+ }
+
+ // use path to delete the physical file from disk
+ delPath := strings.Replace(upload.Path, "/api/", "./", 1)
+ err = os.Remove(delPath)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
func restrict(dir http.Dir) justFilesFilesystem {
return justFilesFilesystem{dir}
}