fix: bug
This commit is contained in:
parent
a18674ce5f
commit
571f7e7c70
2 changed files with 13 additions and 3 deletions
|
@ -53,7 +53,12 @@ func CreatePost(c *gin.Context) {
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
|
||||||
for _, f := range files {
|
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 {
|
if os.Remove(filePath) != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "Internal server error",
|
"error": "Internal server error",
|
||||||
|
@ -97,7 +102,12 @@ func uploadFiles(c *gin.Context, uploadedFiles []*multipart.FileHeader) ([]model
|
||||||
|
|
||||||
splitName := strings.Split(file.Filename, ".")
|
splitName := strings.Split(file.Filename, ".")
|
||||||
newName := uuid.New().String() + "." + splitName[len(splitName)-1]
|
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 {
|
if err := c.SaveUploadedFile(file, path); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -61,7 +61,7 @@ func GetUserById(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var user models.User
|
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 result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue