Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Giger
funkwhale
Commits
ad9a0030
Verified
Commit
ad9a0030
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Implemented AP-to-HTML redirections for tracks, albums, artists and uploads
parent
4f06a433
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/federation/views.py
+32
-1
32 additions, 1 deletion
api/funkwhale_api/federation/views.py
api/tests/federation/test_views.py
+60
-0
60 additions, 0 deletions
api/tests/federation/test_views.py
with
92 additions
and
1 deletion
api/funkwhale_api/federation/views.py
+
32
−
1
View file @
ad9a0030
...
...
@@ -232,7 +232,6 @@ class MusicLibraryViewSet(
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
lb
=
self
.
get_object
()
if
utils
.
should_redirect_ap_to_html
(
request
.
headers
.
get
(
"
accept
"
)):
# XXX: implement this for albums, tracks, artists
return
redirect_to_html
(
lb
.
get_absolute_url
())
conf
=
{
"
id
"
:
lb
.
get_federation_id
(),
...
...
@@ -318,6 +317,14 @@ class MusicUploadViewSet(
serializer_class
=
serializers
.
UploadSerializer
lookup_field
=
"
uuid
"
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
if
utils
.
should_redirect_ap_to_html
(
request
.
headers
.
get
(
"
accept
"
)):
return
redirect_to_html
(
instance
.
track
.
get_absolute_url
())
serializer
=
self
.
get_serializer
(
instance
)
return
response
.
Response
(
serializer
.
data
)
def
get_queryset
(
self
):
queryset
=
super
().
get_queryset
()
actor
=
music_utils
.
get_actor_from_request
(
self
.
request
)
...
...
@@ -340,6 +347,14 @@ class MusicArtistViewSet(
serializer_class
=
serializers
.
ArtistSerializer
lookup_field
=
"
uuid
"
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
if
utils
.
should_redirect_ap_to_html
(
request
.
headers
.
get
(
"
accept
"
)):
return
redirect_to_html
(
instance
.
get_absolute_url
())
serializer
=
self
.
get_serializer
(
instance
)
return
response
.
Response
(
serializer
.
data
)
class
MusicAlbumViewSet
(
FederationMixin
,
mixins
.
RetrieveModelMixin
,
viewsets
.
GenericViewSet
...
...
@@ -352,6 +367,14 @@ class MusicAlbumViewSet(
serializer_class
=
serializers
.
AlbumSerializer
lookup_field
=
"
uuid
"
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
if
utils
.
should_redirect_ap_to_html
(
request
.
headers
.
get
(
"
accept
"
)):
return
redirect_to_html
(
instance
.
get_absolute_url
())
serializer
=
self
.
get_serializer
(
instance
)
return
response
.
Response
(
serializer
.
data
)
class
MusicTrackViewSet
(
FederationMixin
,
mixins
.
RetrieveModelMixin
,
viewsets
.
GenericViewSet
...
...
@@ -370,3 +393,11 @@ class MusicTrackViewSet(
)
serializer_class
=
serializers
.
TrackSerializer
lookup_field
=
"
uuid
"
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
if
utils
.
should_redirect_ap_to_html
(
request
.
headers
.
get
(
"
accept
"
)):
return
redirect_to_html
(
instance
.
get_absolute_url
())
serializer
=
self
.
get_serializer
(
instance
)
return
response
.
Response
(
serializer
.
data
)
This diff is collapsed.
Click to expand it.
api/tests/federation/test_views.py
+
60
−
0
View file @
ad9a0030
...
...
@@ -427,3 +427,63 @@ def test_channel_actor_retrieve_redirects_to_html_if_header_set(
)
assert
response
.
status_code
==
302
assert
response
[
"
Location
"
]
==
expected_url
def
test_upload_retrieve_redirects_to_html_if_header_set
(
factories
,
api_client
,
settings
):
upload
=
factories
[
"
music.Upload
"
](
library__local
=
True
,
playable
=
True
)
url
=
reverse
(
"
federation:music:uploads-detail
"
,
kwargs
=
{
"
uuid
"
:
upload
.
uuid
},)
response
=
api_client
.
get
(
url
,
HTTP_ACCEPT
=
"
text/html
"
)
expected_url
=
utils
.
join_url
(
settings
.
FUNKWHALE_URL
,
utils
.
spa_reverse
(
"
library_track
"
,
kwargs
=
{
"
pk
"
:
upload
.
track
.
pk
}),
)
assert
response
.
status_code
==
302
assert
response
[
"
Location
"
]
==
expected_url
def
test_track_retrieve_redirects_to_html_if_header_set
(
factories
,
api_client
,
settings
):
track
=
factories
[
"
music.Track
"
](
local
=
True
)
url
=
reverse
(
"
federation:music:tracks-detail
"
,
kwargs
=
{
"
uuid
"
:
track
.
uuid
},)
response
=
api_client
.
get
(
url
,
HTTP_ACCEPT
=
"
text/html
"
)
expected_url
=
utils
.
join_url
(
settings
.
FUNKWHALE_URL
,
utils
.
spa_reverse
(
"
library_track
"
,
kwargs
=
{
"
pk
"
:
track
.
pk
}),
)
assert
response
.
status_code
==
302
assert
response
[
"
Location
"
]
==
expected_url
def
test_album_retrieve_redirects_to_html_if_header_set
(
factories
,
api_client
,
settings
):
album
=
factories
[
"
music.Album
"
](
local
=
True
)
url
=
reverse
(
"
federation:music:albums-detail
"
,
kwargs
=
{
"
uuid
"
:
album
.
uuid
},)
response
=
api_client
.
get
(
url
,
HTTP_ACCEPT
=
"
text/html
"
)
expected_url
=
utils
.
join_url
(
settings
.
FUNKWHALE_URL
,
utils
.
spa_reverse
(
"
library_album
"
,
kwargs
=
{
"
pk
"
:
album
.
pk
}),
)
assert
response
.
status_code
==
302
assert
response
[
"
Location
"
]
==
expected_url
def
test_artist_retrieve_redirects_to_html_if_header_set
(
factories
,
api_client
,
settings
):
artist
=
factories
[
"
music.Artist
"
](
local
=
True
)
url
=
reverse
(
"
federation:music:artists-detail
"
,
kwargs
=
{
"
uuid
"
:
artist
.
uuid
},)
response
=
api_client
.
get
(
url
,
HTTP_ACCEPT
=
"
text/html
"
)
expected_url
=
utils
.
join_url
(
settings
.
FUNKWHALE_URL
,
utils
.
spa_reverse
(
"
library_artist
"
,
kwargs
=
{
"
pk
"
:
artist
.
pk
}),
)
assert
response
.
status_code
==
302
assert
response
[
"
Location
"
]
==
expected_url
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment