Skip to content

Commit

Permalink
- Fix constant redeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Choquet committed Mar 17, 2024
1 parent 9344921 commit e0007fd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions directories/deleteDirectory.go
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
package directories

import (
"encoding/json"
fs "filesystem_service/customFs"
"filesystem_service/types"
"net/http"
"strings"
)

func DeleteDirectory(writer http.ResponseWriter, request *http.Request) {
writer.Header().Add("Content-Type", "application/json")
writer.Header().Set("Access-Control-Allow-Origin", "*")

isForce := request.URL.Query().Has("force")

path := fs.GetRoot() + strings.Replace(request.PathValue("path"), "%2F", "/", -1)

d := fs.NewDirectory(path)

var err error
if isForce {
_, err = d.DeepDelete()
} else {
_, err = d.Delete()
}

if err != nil {
writer.WriteHeader(400)
response, _ := json.Marshal(&types.HttpError{
Code: 400,
Message: err.Error(),
})
_, _ = writer.Write(response)
return
}

response, _ := json.Marshal(&types.ResponseStatus{
Status: "success",
})

_, _ = writer.Write(response)
}

0 comments on commit e0007fd

Please sign in to comment.