|
@@ -8,12 +8,15 @@ import (
|
|
|
"os"
|
|
|
"io"
|
|
|
"encoding/json"
|
|
|
+ "os/exec"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
type Config struct {
|
|
|
- FilePath string `json:"filePath"`
|
|
|
- Log string `json:"log"`
|
|
|
- Addr string `json:"addr"`
|
|
|
+ FilePath string `json:"filePath"`
|
|
|
+ DeletePath string `json:"deletePath"`
|
|
|
+ Log string `json:"log"`
|
|
|
+ Addr string `json:"addr"`
|
|
|
}
|
|
|
|
|
|
var Conf = &Config{}
|
|
@@ -80,4 +83,30 @@ func FileUploadHandle(w http.ResponseWriter, r *http.Request) {
|
|
|
log.Debug("FileUploadHandle copy file (%v) success with length(%v)", filename, length)
|
|
|
code = 0
|
|
|
msg = "Ok"
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteFile(w http.ResponseWriter, r *http.Request) {
|
|
|
+ var name = r.FormValue("name")
|
|
|
+ if len(name) < 1 {
|
|
|
+ w.WriteHeader(404)
|
|
|
+ w.Write([]byte("name is empty"))
|
|
|
+ log.Error("DeleteFile name is empty")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var deleteFile= Conf.DeletePath
|
|
|
+ if !strings.HasSuffix(deleteFile, "/") {
|
|
|
+ deleteFile += "/"
|
|
|
+ }
|
|
|
+ cmd := exec.Command("mv", name, Conf.DeletePath)
|
|
|
+ output,err :=cmd.CombinedOutput()
|
|
|
+ if err != nil {
|
|
|
+ w.Write([]byte(err.Error()))
|
|
|
+ log.Error("DeleteFile command with name: %v, output: %v error: %v", name, deleteFile, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Debug("DeleteFile command with name: %v, output: %v success with output: %v", name, deleteFile, string(output))
|
|
|
+ w.Write([]byte("Success"))
|
|
|
+ return
|
|
|
}
|