diff --git a/Dockerfile b/Dockerfile index 0081924..d976cc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM golang:latest +FROM golang:1.22 # Set destination for COPY WORKDIR /app diff --git a/main.go b/main.go index 16626e8..142e0f5 100644 --- a/main.go +++ b/main.go @@ -85,7 +85,13 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { FileSize: fileHeader.Size, } - chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, API_Key, PostData) + UploadHeaders := map[string]string{ + "X-Api-Key": API_Key, + "Content-Type": "application/json", + "X-Real-IP": r.RemoteAddr, + } + + chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, UploadHeaders, PostData) if err != nil { http.Error(w, handler.ErrorResponseBuild(http.StatusBadRequest, "Something went wrong!"), http.StatusBadRequest) handler.ErrorLogBuilder([]string{r.RemoteAddr, tempfilepath}, err.Error()) @@ -120,7 +126,13 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { Identifier: chibisafe_Response_Metadata.Identifier, } - PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, API_Key, PostProcessData) + ProcessHeaders := map[string]string{ + "X-Api-Key": API_Key, + "Content-Type": "application/json", + "X-Real-IP": r.RemoteAddr, + } + + PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, ProcessHeaders, PostProcessData) if err != nil { http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError) handler.ErrorLogBuilder([]string{r.RemoteAddr, chibisafe_Response_Metadata.Identifier, tempfilepath}, err.Error()) diff --git a/src/handler/chibisafe.go b/src/handler/chibisafe.go index d48cea2..c5c20b9 100644 --- a/src/handler/chibisafe.go +++ b/src/handler/chibisafe.go @@ -31,7 +31,7 @@ func Check_API_Key(Basepath string, accessKey string) bool { return resp.StatusCode == http.StatusOK } -func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]byte, error) { +func UploadPost(BasePath string, headers map[string]string, PostData UploadPostMeta) ([]byte, error) { URL := BasePath + "/api/upload" // Convert PostData to JSON PostDataJson, err := json.Marshal(PostData) @@ -39,11 +39,6 @@ func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]b return nil, err } - headers := map[string]string{ - "X-Api-Key": accessKey, - "Content-Type": "application/json", - } - POSTStruct := URLRequest{ URL: URL, ContentType: PostData.ContentType, @@ -114,7 +109,7 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte, } } -func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcessMeta) ([]byte, error) { +func UploadProcessPost(BasePath string, headers map[string]string, PostData UploadProcessMeta) ([]byte, error) { URL := BasePath + "/api/upload/process" // Convert PostData to JSON PostDataJson, err := json.Marshal(PostData) @@ -122,11 +117,6 @@ func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcess return nil, err } - headers := map[string]string{ - "X-Api-Key": accessKey, - "Content-Type": "application/json", - } - POSTStruct := URLRequest{ URL: URL, Method: "POST",