fix : code cleanup

This commit is contained in:
minoplhy 2024-04-10 23:30:23 +07:00
parent c45dbce606
commit 2c2f6a24d2
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF
4 changed files with 14 additions and 9 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
uploads
activity.log
activity.log
docker-compose.yml

View File

@ -90,7 +90,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
FileSize: fileHeader.Size,
}
chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, PostData, API_Key)
chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, API_Key, PostData)
if err != nil {
http.Error(w, handler.ErrorResponseBuild(http.StatusBadRequest, "Something went wrong!"), http.StatusBadRequest)
handler.LogBuilder("ERROR", []string{r.RemoteAddr, tempfilepath}, err.Error())
@ -114,13 +114,18 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
}
handler.LogBuilder("INFO", []string{r.RemoteAddr, chibisafe_Response_Metadata.Identifier, tempfilepath}, "Successfully PUT file to Network Storage")
// Build Struct for PostProcess Json
//
// Name -> original Filename
// ContentType -> original Content-Type
// Identifier -> File Identifier ID
PostProcessData := handler.UploadProcessMeta{
Name: fileHeader.Filename,
ContentType: fileHeader.Header.Get("Content-Type"),
Identifier: chibisafe_Response_Metadata.Identifier,
}
PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, PostData.ContentType, chibisafe_Response_Metadata.Identifier, API_Key, PostProcessData)
PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, API_Key, PostProcessData)
if err != nil {
http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError)
handler.LogBuilder("ERROR", []string{r.RemoteAddr, chibisafe_Response_Metadata.Identifier, tempfilepath}, err.Error())

View File

@ -27,7 +27,7 @@ func Check_API_Key(Basepath string, accessKey string) bool {
return resp.StatusCode == http.StatusOK
}
func UploadPost(BasePath string, PostData UploadPostMeta, accessKey string) ([]byte, error) {
func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]byte, error) {
URL := BasePath + "/api/upload"
// Convert PostData to JSON
PostDataJson, err := json.Marshal(PostData)
@ -110,7 +110,7 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
}
}
func UploadProcessPost(BasePath string, ContentType string, Identifier string, accessKey string, PostData UploadProcessMeta) ([]byte, error) {
func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcessMeta) ([]byte, error) {
URL := BasePath + "/api/upload/process"
// Convert PostData to JSON
PostDataJson, err := json.Marshal(PostData)
@ -124,10 +124,9 @@ func UploadProcessPost(BasePath string, ContentType string, Identifier string, a
}
POSTStruct := URLRequest{
URL: URL,
ContentType: ContentType,
Method: "POST",
Header: headers,
URL: URL,
Method: "POST",
Header: headers,
}
resp, err := HTTPBytes(POSTStruct, bytes.NewBuffer(PostDataJson))