summaryrefslogtreecommitdiff
path: root/system/admin/filesystem.go
diff options
context:
space:
mode:
Diffstat (limited to 'system/admin/filesystem.go')
-rw-r--r--system/admin/filesystem.go31
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}
}