Skip to content

Commit 2dc8368

Browse files
author
broccoli
committed
fix: all uploaded files are added to file_record
+ uploaded avatar and branding files are added to the file_record table, so that the table provides a comprehensive overview of files in the file system
1 parent aebb7d4 commit 2dc8368

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

internal/service/uploader/upload.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ func (us *uploaderService) UploadAvatarFile(ctx *gin.Context, userID string) (ur
127127

128128
newFilename := fmt.Sprintf("%s%s", uid.IDStr12(), fileExt)
129129
avatarFilePath := path.Join(constant.AvatarSubPath, newFilename)
130-
return us.uploadImageFile(ctx, fileHeader, avatarFilePath)
130+
url, err = us.uploadImageFile(ctx, fileHeader, avatarFilePath)
131+
if err != nil {
132+
return "", err
133+
}
134+
us.fileRecordService.AddFileRecord(ctx, userID, avatarFilePath, url, string(plugin.UserAvatar))
135+
return url, nil
136+
131137
}
132138

133139
func (us *uploaderService) AvatarThumbFile(ctx *gin.Context, fileName string, size int) (url string, err error) {
@@ -282,7 +288,13 @@ func (us *uploaderService) UploadBrandingFile(ctx *gin.Context, userID string) (
282288

283289
newFilename := fmt.Sprintf("%s%s", uid.IDStr12(), fileExt)
284290
avatarFilePath := path.Join(constant.BrandingSubPath, newFilename)
285-
return us.uploadImageFile(ctx, fileHeader, avatarFilePath)
291+
url, err = us.uploadImageFile(ctx, fileHeader, avatarFilePath)
292+
if err != nil {
293+
return "", err
294+
}
295+
us.fileRecordService.AddFileRecord(ctx, userID, avatarFilePath, url, string(plugin.AdminBranding))
296+
return url, nil
297+
286298
}
287299

288300
func (us *uploaderService) uploadImageFile(ctx *gin.Context, file *multipart.FileHeader, fileSubPath string) (

0 commit comments

Comments
 (0)