From 14258420d4de4f0fafbb618971d29db1092324f4 Mon Sep 17 00:00:00 2001 From: Nicolas Choquet Date: Sun, 17 Mar 2024 05:14:15 +0100 Subject: [PATCH] - Fix constant redeclaration --- auth/checkToken.go | 15 +++++++++++++++ directories/deleteDirectory.go | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/auth/checkToken.go b/auth/checkToken.go index 0a14ab0..4d79bd8 100644 --- a/auth/checkToken.go +++ b/auth/checkToken.go @@ -1,8 +1,10 @@ package auth import ( + "encoding/json" "filesystem_service/customHttp" "filesystem_service/data" + "filesystem_service/types" "fmt" "net/http" "strings" @@ -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 +} diff --git a/directories/deleteDirectory.go b/directories/deleteDirectory.go index 1a5564e..f77313d 100644 --- a/directories/deleteDirectory.go +++ b/directories/deleteDirectory.go @@ -2,6 +2,7 @@ package directories import ( "encoding/json" + "filesystem_service/auth" fs "filesystem_service/customFs" "filesystem_service/types" "net/http" @@ -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)