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
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( user.avatar).decode("utf-8")
def test_get_cover_art_album(factories, logged_in_api_client): url = reverse("api:subsonic-get_cover_art") assert url.endswith("getCoverArt") is True album = factories["music.Album"](with_cover=True) response = logged_in_api_client.get(url, {"id": "al-{}".format(album.pk)}) assert response.status_code == 200 assert response["Content-Type"] == "" assert response["X-Accel-Redirect"] == music_views.get_file_path( album.attachment_cover.file).decode("utf-8")
def test_serve_file_in_place_utf8(proxy, serve_path, expected, factories, api_client, settings, preferences): preferences["common__api_authentication_required"] = False settings.PROTECT_FILE_PATH = "/_protected/music" settings.REVERSE_PROXY_TYPE = proxy settings.MUSIC_DIRECTORY_PATH = "/app/music" settings.MUSIC_DIRECTORY_SERVE_PATH = serve_path path = views.get_file_path("/app/music/hello/worldéà.mp3") assert path == expected.encode("utf-8")
def test_get_cover_art_attachment(factories, logged_in_api_client): attachment = factories["common.Attachment"]() url = reverse("api:subsonic-get_cover_art") assert url.endswith("getCoverArt") is True response = logged_in_api_client.get( url, {"id": "at-{}".format(attachment.uuid)}) assert response.status_code == 200 assert response["Content-Type"] == "" assert response["X-Accel-Redirect"] == music_views.get_file_path( attachment.file).decode("utf-8")
def get_cover_art(self, request, *args, **kwargs): data = request.GET or request.POST id = data.get("id", "") if not id: return response.Response({ "error": { "code": 10, "message": "cover art ID must be specified." } }) if id.startswith("al-"): try: album_id = int(id.replace("al-", "")) album = (music_models.Album.objects.exclude( attachment_cover=None).select_related( "attachment_cover").get(pk=album_id)) except (TypeError, ValueError, music_models.Album.DoesNotExist): return response.Response( {"error": { "code": 70, "message": "cover art not found." }}) attachment = album.attachment_cover elif id.startswith("at-"): try: attachment_id = id.replace("at-", "") attachment = common_models.Attachment.objects.get( uuid=attachment_id) except (TypeError, ValueError, music_models.Album.DoesNotExist): return response.Response( {"error": { "code": 70, "message": "cover art not found." }}) else: return response.Response( {"error": { "code": 70, "message": "cover art not found." }}) if not attachment.file: common_tasks.fetch_remote_attachment(attachment) cover = attachment.file mapping = {"nginx": "X-Accel-Redirect", "apache2": "X-Sendfile"} path = music_views.get_file_path(cover) 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
def get_cover_art(self, request, *args, **kwargs): data = request.GET or request.POST id = data.get("id", "") if not id: return response.Response({ "error": { "code": 10, "message": "cover art ID must be specified." } }) if id.startswith("al-"): try: album_id = int(id.replace("al-", "")) album = (music_models.Album.objects.exclude( cover__isnull=True).exclude(cover="").get(pk=album_id)) except (TypeError, ValueError, music_models.Album.DoesNotExist): return response.Response( {"error": { "code": 70, "message": "cover art not found." }}) cover = album.cover else: return response.Response( {"error": { "code": 70, "message": "cover art not found." }}) mapping = {"nginx": "X-Accel-Redirect", "apache2": "X-Sendfile"} path = music_views.get_file_path(cover) 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