add option for avatar/profileBg download

This commit is contained in:
2026-04-19 01:20:23 +02:00
parent a0140ec0a7
commit 61936b4576
3 changed files with 83 additions and 3 deletions
@@ -5,6 +5,7 @@ import (
"net/http"
"strings"
"go-socket/packages/convertions"
"go-socket/packages/globals"
"go-socket/packages/minio"
)
@@ -55,6 +56,83 @@ func HandleAttachmentFileUpload(response http.ResponseWriter, request *http.Requ
response.Write([]byte(key))
}
func HandleGetUserAvatar(response http.ResponseWriter, request *http.Request) {
if !postValidCheckWithResponseOnFail(&response, request, postNormal) {
return
}
ctx := request.Context()
_, err := getUserByToken(ctx, request.Header.Get("token"))
if err != nil {
http.Error(response, "invalid token", http.StatusUnauthorized)
return
}
targetId, err := convertions.ConvertStringUuid(request.FormValue("userid"))
if err != nil {
http.Error(response, "invalid userid", http.StatusBadRequest)
return
}
target, err := getUserById(ctx, targetId)
if err != nil {
http.Error(response, "user not found", http.StatusNotFound)
return
}
if target.Avatar == "" {
http.Error(response, "no avatar", http.StatusNotFound)
return
}
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, string(minio.UserAvatarPrefix)+target.Avatar)
if err != nil {
http.Error(response, "internal server error", http.StatusInternalServerError)
return
}
response.WriteHeader(http.StatusOK)
response.Write([]byte(url.String()))
}
func HandleGetUserProfileBg(response http.ResponseWriter, request *http.Request) {
if !postValidCheckWithResponseOnFail(&response, request, postNormal) {
return
}
ctx := request.Context()
if _, err := getUserByToken(ctx, request.Header.Get("token")); err != nil {
http.Error(response, "invalid token", http.StatusUnauthorized)
return
}
targetId, err := convertions.ConvertStringUuid(request.FormValue("userid"))
if err != nil {
http.Error(response, "invalid userid", http.StatusBadRequest)
return
}
target, err := getUserById(ctx, targetId)
if err != nil {
http.Error(response, "user not found", http.StatusNotFound)
return
}
if target.ProfileBg == "" {
http.Error(response, "no profile background", http.StatusNotFound)
return
}
url, _, err := minio.GetDownloadUrlAndMetadata(ctx, string(minio.UserProfileBgPrefix)+target.ProfileBg)
if err != nil {
http.Error(response, "internal server error", http.StatusInternalServerError)
return
}
response.WriteHeader(http.StatusOK)
response.Write([]byte(url.String()))
}
func HandleAttachmentFileDownload(response http.ResponseWriter, request *http.Request) {
if !postValidCheckWithResponseOnFail(&response, request, postNormal) {
return
+2 -1
View File
@@ -2,9 +2,10 @@ package httpRequest
import (
"context"
"go-socket/packages/convertions"
"net/http"
"go-socket/packages/convertions"
"go-socket/packages/cache"
"go-socket/packages/postgresql"
"go-socket/packages/tokens"
+3 -2
View File
@@ -1,4 +1,5 @@
more user customization (avatar, banners, desc)
add hubs
user banners
Alan's sun