Verified Commit d3e411fa authored by Agate's avatar Agate 💬

See #574: Implemented getAvatar view

parent 6c7ee54d
......@@ -15,6 +15,7 @@ from import models as music_models
from import utils
from import views as music_views
from funkwhale_api.playlists import models as playlists_models
from funkwhale_api.users import models as users_models
from . import authentication, filters, negotiation, serializers
......@@ -426,6 +427,23 @@ class SubsonicViewSet(viewsets.GenericViewSet):
data = {"playlist": serializers.get_playlist_detail_data(playlist)}
return response.Response(data)
@list_route(methods=["get", "post"], url_name="get_avatar", url_path="getAvatar")
def get_avatar(self, request, *args, **kwargs):
user = kwargs.pop("obj")
mapping = {"nginx": "X-Accel-Redirect", "apache2": "X-Sendfile"}
path = music_views.get_file_path(user.avatar)
file_header = mapping[settings.REVERSE_PROXY_TYPE]
# let the proxy set the content-type
r = response.Response({}, content_type="")
r[file_header] = path
return r
methods=["get", "post"],
......@@ -457,6 +457,19 @@ def test_get_cover_art_album(factories, logged_in_api_client):
def test_get_avatar(factories, logged_in_api_client):
user = factories["users.User"]()
url = reverse("api:subsonic-get-avatar")
assert url.endswith("getAvatar") is True
response = logged_in_api_client.get(url, {"username": user.username})
assert response.status_code == 200
assert response["Content-Type"] == ""
assert response["X-Accel-Redirect"] == music_views.get_file_path(
def test_scrobble(factories, logged_in_api_client):
upload = factories["music.Upload"]()
track = upload.track
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment