mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 23:18:26 +02:00
See #574: Implemented getAvatar view
This commit is contained in:
parent
6c7ee54dbc
commit
d3e411fa97
2 changed files with 31 additions and 0 deletions
|
@ -15,6 +15,7 @@ from funkwhale_api.music import models as music_models
|
|||
from funkwhale_api.music import utils
|
||||
from funkwhale_api.music 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")
|
||||
@find_object(
|
||||
queryset=users_models.User.objects.exclude(avatar=None).exclude(avatar=""),
|
||||
model_field="username__iexact",
|
||||
field="username",
|
||||
cast=str,
|
||||
)
|
||||
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
|
||||
|
||||
@list_route(
|
||||
methods=["get", "post"],
|
||||
url_name="get_music_folders",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue