add option for avatar/profilebg change
This commit is contained in:
+16
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user