getting user; mod: avatar, profileBg, profile now working
This commit is contained in:
@@ -266,6 +266,7 @@ func HandleUserDeleteConnection(response http.ResponseWriter, request *http.Requ
|
||||
})
|
||||
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
response.Write(conn.Id[:])
|
||||
}
|
||||
|
||||
func HandleUserElevateConnection(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
@@ -42,7 +42,11 @@ func HandleAttachmentFileUpload(response http.ResponseWriter, request *http.Requ
|
||||
defer file.Close()
|
||||
|
||||
contentType := header.Header.Get("Content-Type")
|
||||
key := minio.GetKey(conn.Id, contentType, minio.File)
|
||||
key := minio.GetKey(minio.GetKeyOptions{
|
||||
ConnectionId: conn.Id,
|
||||
MimeType: contentType,
|
||||
UploadType: minio.File,
|
||||
})
|
||||
|
||||
if err = minio.Upload(ctx, key, file, header.Size, contentType, map[string]string{
|
||||
"originalName": header.Filename,
|
||||
@@ -85,7 +89,7 @@ func HandleGetUserAvatar(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, string(minio.UserAvatarPrefix)+target.Avatar)
|
||||
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, target.Avatar)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -123,7 +127,7 @@ func HandleGetUserProfileBg(response http.ResponseWriter, request *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, string(minio.UserProfileBgPrefix)+target.ProfileBg)
|
||||
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, target.ProfileBg)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -209,11 +209,6 @@ func HandleUserModAvatar(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
file, header, err := request.FormFile("file")
|
||||
if err != nil {
|
||||
http.Error(response, "missing file", http.StatusBadRequest)
|
||||
@@ -228,14 +223,18 @@ func HandleUserModAvatar(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
if user.Avatar != "" {
|
||||
err = minio.Delete(ctx, string(minio.UserAvatarPrefix)+user.Avatar)
|
||||
err = minio.Delete(ctx, user.Avatar)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
key := minio.GetKey(conn.Id, contentType, minio.File)
|
||||
key := minio.GetKey(minio.GetKeyOptions{
|
||||
UserId: user.Id,
|
||||
MimeType: contentType,
|
||||
UploadType: minio.UserAvatar,
|
||||
})
|
||||
if err = minio.Upload(ctx, key, file, header.Size, contentType, map[string]string{
|
||||
"originalName": header.Filename,
|
||||
"uploaderId": user.Id.String(),
|
||||
@@ -244,7 +243,7 @@ func HandleUserModAvatar(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user.Avatar = key[len(minio.UserAvatarPrefix):]
|
||||
user.Avatar = key
|
||||
err = postgresql.UserUpdateProfile(ctx, user, types.UserProfileUpdateList{Avatar: true})
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
@@ -273,11 +272,6 @@ func HandleUserModProfileBg(response http.ResponseWriter, request *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
file, header, err := request.FormFile("file")
|
||||
if err != nil {
|
||||
http.Error(response, "missing file", http.StatusBadRequest)
|
||||
@@ -292,14 +286,18 @@ func HandleUserModProfileBg(response http.ResponseWriter, request *http.Request)
|
||||
}
|
||||
|
||||
if user.ProfileBg != "" {
|
||||
err = minio.Delete(ctx, string(minio.UserProfileBgPrefix)+user.ProfileBg)
|
||||
err = minio.Delete(ctx, user.ProfileBg)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
key := minio.GetKey(conn.Id, contentType, minio.UserProfileBg)
|
||||
key := minio.GetKey(minio.GetKeyOptions{
|
||||
UserId: user.Id,
|
||||
MimeType: contentType,
|
||||
UploadType: minio.UserProfileBg,
|
||||
})
|
||||
if err = minio.Upload(ctx, key, file, header.Size, contentType, map[string]string{
|
||||
"originalName": header.Filename,
|
||||
"uploaderId": user.Id.String(),
|
||||
@@ -308,7 +306,7 @@ func HandleUserModProfileBg(response http.ResponseWriter, request *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
user.ProfileBg = key[len(minio.UserProfileBgPrefix):]
|
||||
user.ProfileBg = key
|
||||
err = postgresql.UserUpdateProfile(ctx, user, types.UserProfileUpdateList{ProfileBg: true})
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user