diff --git a/controllers/postController.go b/controllers/postController.go index c9b2a88..7af2434 100644 --- a/controllers/postController.go +++ b/controllers/postController.go @@ -53,7 +53,12 @@ func CreatePost(c *gin.Context) { if result.Error != nil { for _, f := range files { - filePath := filepath.Join("assets", f.FileName) + var filePath string + if os.Getenv("GIN_MODE") == "release" { + filePath = filepath.Join(initializers.ReleaseBasePath, f.FileName) + } else { + filePath = filepath.Join(initializers.DebugBasePath, f.FileName) + } if os.Remove(filePath) != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": "Internal server error", @@ -97,7 +102,12 @@ func uploadFiles(c *gin.Context, uploadedFiles []*multipart.FileHeader) ([]model splitName := strings.Split(file.Filename, ".") newName := uuid.New().String() + "." + splitName[len(splitName)-1] - path := "assets/" + newName + var path string + if os.Getenv("GIN_MODE") == "release" { + path = initializers.ReleaseBasePath + newName + } else { + path = initializers.DebugBasePath + newName + } if err := c.SaveUploadedFile(file, path); err != nil { return nil, err diff --git a/controllers/userController.go b/controllers/userController.go index 636a45f..e457632 100644 --- a/controllers/userController.go +++ b/controllers/userController.go @@ -61,7 +61,7 @@ func GetUserById(c *gin.Context) { } var user models.User - result := initializers.DB.Preload("Posts").Preload("Files").First(&user, "id = ?", uniqueId) + result := initializers.DB.Preload("Posts.Files").First(&user, "id = ?", uniqueId) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) {