add dynamic profile update, connection helper, file download metadata
- replace UserSetColor/UserSetPronouns with single UserUpdateProfile that dynamically builds one UPDATE query from UserProfileUpdateList - add getConnectionWithResponseOnFail helper to deduplicate connection ID parsing and validation across handlers - rename file.go to attachmentFile.go and update handler names - GetDownloadUrlAndMetadata now fetches object metadata via StatObject and returns it alongside the presigned URL - file download endpoint returns JSON with url and originalName - add description field to user and DB schema - remove unused ConnectionState variants (GroupFellow, GroupFriend) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+28
-6
@@ -17,12 +17,28 @@ import (
|
||||
|
||||
var minClient *minio.Client
|
||||
|
||||
func GetKey(connectionId uuid.UUID, mimeType string) string {
|
||||
type DataType uint8
|
||||
|
||||
const (
|
||||
File DataType = iota
|
||||
UserAvatar
|
||||
UserProfileBg
|
||||
)
|
||||
|
||||
func GetKey(connectionId uuid.UUID, mimeType string, uploadType DataType) string {
|
||||
extensions, err := mime.ExtensionsByType(mimeType)
|
||||
if err != nil || len(extensions) == 0 {
|
||||
extensions = []string{".unknown"}
|
||||
}
|
||||
return connectionId.String() + "/" + strconv.FormatInt(time.Now().UnixMilli(), 10) + extensions[0]
|
||||
|
||||
key := connectionId.String() + "/" + strconv.FormatInt(time.Now().UnixMilli(), 10) + extensions[0]
|
||||
|
||||
if uploadType == UserAvatar {
|
||||
return "userAvatar/" + key
|
||||
} else if uploadType == UserProfileBg {
|
||||
return "userProfileBg/" + key
|
||||
}
|
||||
return "upload/" + key
|
||||
}
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
@@ -30,7 +46,7 @@ func Init(ctx context.Context) {
|
||||
minClient, err = minio.New("localhost:9000", &minio.Options{
|
||||
Creds: credentials.NewStaticV4("root", "change_to_env", ""),
|
||||
Secure: false,
|
||||
}) // TODO change in production
|
||||
}) // TODO change for production
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -49,7 +65,6 @@ func Init(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Upload(ctx context.Context, key string, body io.Reader, size int64, contentType string, metadata map[string]string) error {
|
||||
@@ -65,9 +80,16 @@ func Upload(ctx context.Context, key string, body io.Reader, size int64, content
|
||||
return err
|
||||
}
|
||||
|
||||
func GetDownloadUrl(ctx context.Context, key string) (*url.URL, error) {
|
||||
func GetDownloadUrlAndMetadata(ctx context.Context, key string) (*url.URL, map[string]string, error) {
|
||||
info, err := minClient.StatObject(ctx, globals.FileStorageBucketName, key, minio.StatObjectOptions{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
u, err := minClient.PresignedGetObject(ctx, globals.FileStorageBucketName, key, globals.FileDownloadLinkTtl, nil)
|
||||
return u, err
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return u, info.UserMetadata, nil
|
||||
}
|
||||
|
||||
func DoesExist(ctx context.Context, key string) bool {
|
||||
|
||||
Reference in New Issue
Block a user