mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-25 11:29:53 +01:00
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:
parent
61bb68fc6b
commit
16c62e075e
4 changed files with 211 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue