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 e0007fd commit 1425842
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions auth/checkToken.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package auth

import (
"encoding/json"
"filesystem_service/customHttp"
"filesystem_service/data"
"filesystem_service/types"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -48,3 +50,16 @@ func CheckToken(request *http.Request) (bool, error) {

return true, nil
}

func IsAuthorized(writer http.ResponseWriter, request *http.Request) bool {
if _, err := CheckToken(request); err != nil {
writer.WriteHeader(403)
response, _ := json.Marshal(&types.HttpError{
Code: 403,
Message: err.Error(),
})
_, _ = writer.Write(response)
return false
}
return true
}
5 changes: 5 additions & 0 deletions directories/deleteDirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package directories

import (
"encoding/json"
"filesystem_service/auth"
fs "filesystem_service/customFs"
"filesystem_service/types"
"net/http"
Expand All @@ -12,6 +13,10 @@ func DeleteDirectory(writer http.ResponseWriter, request *http.Request) {
writer.Header().Add("Content-Type", "application/json")
writer.Header().Set("Access-Control-Allow-Origin", "*")

if !auth.IsAuthorized(writer, request) {
return
}

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

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

0 comments on commit 1425842

Please sign in to comment.