user no stays in cache forever, fix some hubs bugs and add new enpoints
This commit is contained in:
@@ -551,6 +551,74 @@ func HandleHubSetBg(response http.ResponseWriter, request *http.Request) {
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
|
||||
func HandleGetHubIcon(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
ctx := request.Context()
|
||||
_, _, hub, err := getHubUserIfValidWithResponseOnFail(ctx, response, request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if hub.IconUrl == "" {
|
||||
http.Error(response, "hub has no icon", http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
url, meta, err := minio.GetDownloadUrlAndMetadata(ctx, hub.IconUrl)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
iconData, err := json.Marshal(map[string]any{
|
||||
"url": url.String(),
|
||||
"metadata": meta,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(response, "json error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteHeader(http.StatusOK)
|
||||
response.Write(iconData)
|
||||
}
|
||||
|
||||
func HandleGetHubBg(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
ctx := request.Context()
|
||||
_, _, hub, err := getHubUserIfValidWithResponseOnFail(ctx, response, request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if hub.BgUrl == "" {
|
||||
http.Error(response, "hub has no background", http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
url, meta, err := minio.GetDownloadUrlAndMetadata(ctx, hub.BgUrl)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
bgData, err := json.Marshal(map[string]any{
|
||||
"url": url.String(),
|
||||
"metadata": meta,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(response, "json error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteHeader(http.StatusOK)
|
||||
response.Write(bgData)
|
||||
}
|
||||
|
||||
func HandleHubRemove(response http.ResponseWriter, request *http.Request) {
|
||||
_, hub, _, _, ok := hubPermissionContext(response, request, normal, types.PermissionRemoveHub)
|
||||
if !ok {
|
||||
@@ -852,7 +920,7 @@ func HandleRoleSetColor(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
color, err := convertions.StringToRgba(request.FormValue("new_color"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid newcolor", http.StatusBadRequest)
|
||||
http.Error(response, "invalid new_color", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user