feat(nativeapi): add user avatar upload and delete endpoints

Adds POST/DELETE /api/user/{id}/image, gated by EnableUserAvatarUpload
(never EnableArtworkUpload) and restricted to the target user or an
admin. Reuses the artist/playlist/radio image-upload handlers via a new
gate opt-out so their EnableArtworkUpload behavior is unchanged.
This commit is contained in:
Deluan 2026-09-07 19:31:51 -04:00
commit 16c62e075e
4 changed files with 211 additions and 3 deletions

View file

@ -31,10 +31,16 @@ func checkImageUploadPermission(w http.ResponseWriter, r *http.Request) bool {
}
func handleImageUpload(saveFn func(ctx context.Context, reader io.Reader, ext string) error) http.HandlerFunc {
return handleImageUploadGated(true, saveFn)
}
// handleImageUploadGated is handleImageUpload with an opt-out from the EnableArtworkUpload gate,
// so avatar uploads (gated separately by EnableUserAvatarUpload) can reuse this handler.
func handleImageUploadGated(checkArtworkFlag bool, saveFn func(ctx context.Context, reader io.Reader, ext string) error) http.HandlerFunc {
maxImageSize := artwork.MaxImageUploadSize()
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if !checkImageUploadPermission(w, r) {
if checkArtworkFlag && !checkImageUploadPermission(w, r) {
return
}
r.Body = http.MaxBytesReader(w, r.Body, maxImageSize)
@ -97,9 +103,15 @@ func handleImageUpload(saveFn func(ctx context.Context, reader io.Reader, ext st
}
func handleImageDelete(deleteFn func(ctx context.Context) error) http.HandlerFunc {
return handleImageDeleteGated(true, deleteFn)
}
// handleImageDeleteGated is handleImageDelete with the same EnableArtworkUpload opt-out as
// handleImageUploadGated.
func handleImageDeleteGated(checkArtworkFlag bool, deleteFn func(ctx context.Context) error) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if !checkImageUploadPermission(w, r) {
if checkArtworkFlag && !checkImageUploadPermission(w, r) {
return
}
if err := deleteFn(ctx); err != nil {