add option for avatar/profilebg change

This commit is contained in:
2026-04-19 00:06:17 +02:00
parent c85c66e43a
commit a47654428c
9 changed files with 187 additions and 31 deletions
+16 -3
View File
@@ -25,6 +25,14 @@ const (
UserProfileBg
)
type DataTypePrefix string
const (
FilePrefix DataTypePrefix = "upload/"
UserAvatarPrefix DataTypePrefix = "userAvatar/"
UserProfileBgPrefix DataTypePrefix = "userProfileBg/"
)
func GetKey(connectionId uuid.UUID, mimeType string, uploadType DataType) string {
extensions, err := mime.ExtensionsByType(mimeType)
if err != nil || len(extensions) == 0 {
@@ -34,11 +42,11 @@ func GetKey(connectionId uuid.UUID, mimeType string, uploadType DataType) string
key := connectionId.String() + "/" + strconv.FormatInt(time.Now().UnixMilli(), 10) + extensions[0]
if uploadType == UserAvatar {
return "userAvatar/" + key
return string(UserAvatarPrefix) + key
} else if uploadType == UserProfileBg {
return "userProfileBg/" + key
return string(UserProfileBgPrefix) + key
}
return "upload/" + key
return string(FilePrefix) + key
}
func Init(ctx context.Context) {
@@ -96,3 +104,8 @@ func DoesExist(ctx context.Context, key string) bool {
_, err := minClient.StatObject(ctx, globals.FileStorageBucketName, key, minio.StatObjectOptions{})
return err == nil
}
func Delete(ctx context.Context, key string) error {
err := minClient.RemoveObject(ctx, globals.FileStorageBucketName, key, minio.RemoveObjectOptions{})
return err
}