Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
interfect
funkwhale
Commits
dda1cd25
Verified
Commit
dda1cd25
authored
Apr 12, 2018
by
Eliot Berriot
Browse files
Added scan endpoint to trigger a scan for a library
parent
077a17b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/federation/serializers.py
View file @
dda1cd25
...
...
@@ -176,6 +176,10 @@ class APILibrarySerializer(serializers.ModelSerializer):
]
+
read_only_fields
class
APILibraryScanSerializer
(
serializers
.
Serializer
):
until
=
serializers
.
DateTimeField
(
required
=
False
)
class
APILibraryCreateSerializer
(
serializers
.
ModelSerializer
):
actor
=
serializers
.
URLField
()
federation_enabled
=
serializers
.
BooleanField
()
...
...
api/funkwhale_api/federation/views.py
View file @
dda1cd25
...
...
@@ -25,6 +25,7 @@ from . import models
from
.
import
permissions
from
.
import
renderers
from
.
import
serializers
from
.
import
tasks
from
.
import
utils
from
.
import
webfinger
...
...
@@ -186,7 +187,7 @@ class LibraryViewSet(
)
@
list_route
(
methods
=
[
'get'
])
def
scan
(
self
,
request
,
*
args
,
**
kwargs
):
def
fetch
(
self
,
request
,
*
args
,
**
kwargs
):
account
=
request
.
GET
.
get
(
'account'
)
if
not
account
:
return
response
.
Response
(
...
...
@@ -195,6 +196,19 @@ class LibraryViewSet(
data
=
library
.
scan_from_account_name
(
account
)
return
response
.
Response
(
data
)
@
detail_route
(
methods
=
[
'post'
])
def
scan
(
self
,
request
,
*
args
,
**
kwargs
):
library
=
self
.
get_object
()
serializer
=
serializers
.
APILibraryScanSerializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
id
=
tasks
.
scan_library
.
delay
(
library_id
=
library
.
pk
,
until
=
serializer
.
validated_data
[
'until'
]
)
return
response
.
Response
({
'task'
:
id
})
@
list_route
(
methods
=
[
'get'
])
def
following
(
self
,
request
,
*
args
,
**
kwargs
):
library_actor
=
actors
.
SYSTEM_ACTORS
[
'library'
].
get_actor_instance
()
...
...
api/tests/federation/test_views.py
View file @
dda1cd25
from
django.urls
import
reverse
from
django.core.paginator
import
Paginator
from
django.urls
import
reverse
from
django.utils
import
timezone
import
pytest
...
...
@@ -168,13 +169,13 @@ def test_library_actor_includes_library_link(db, settings, api_client):
assert
response
.
data
[
'url'
]
==
expected_links
def
test_can_
scan
_library
(
superuser_api_client
,
mocker
):
def
test_can_
fetch
_library
(
superuser_api_client
,
mocker
):
result
=
{
'test'
:
'test'
}
scan
=
mocker
.
patch
(
'funkwhale_api.federation.library.scan_from_account_name'
,
return_value
=
result
)
url
=
reverse
(
'api:v1:federation:libraries-
scan
'
)
url
=
reverse
(
'api:v1:federation:libraries-
fetch
'
)
response
=
superuser_api_client
.
get
(
url
,
data
=
{
'account'
:
'test@test.library'
})
...
...
@@ -306,3 +307,25 @@ def test_can_patch_library(factories, superuser_api_client):
for
k
,
v
in
data
.
items
():
assert
getattr
(
library
,
k
)
==
v
def
test_scan_library
(
factories
,
mocker
,
superuser_api_client
):
scan
=
mocker
.
patch
(
'funkwhale_api.federation.tasks.scan_library.delay'
,
return_value
=
'id'
)
library
=
factories
[
'federation.Library'
]()
now
=
timezone
.
now
()
data
=
{
'until'
:
now
,
}
url
=
reverse
(
'api:v1:federation:libraries-scan'
,
kwargs
=
{
'uuid'
:
str
(
library
.
uuid
)})
response
=
superuser_api_client
.
post
(
url
,
data
)
assert
response
.
status_code
==
200
assert
response
.
data
==
{
'task'
:
'id'
}
scan
.
assert_called_once_with
(
library_id
=
library
.
pk
,
until
=
now
)
front/src/components/federation/LibraryForm.vue
View file @
dda1cd25
...
...
@@ -72,7 +72,7 @@ export default {
this
.
isLoading
=
true
self
.
errors
=
[]
self
.
result
=
null
axios
.
get
(
'
/federation/libraries/
scan
/
'
,
{
params
:
{
account
:
this
.
libraryUsername
}}).
then
((
response
)
=>
{
axios
.
get
(
'
/federation/libraries/
fetch
/
'
,
{
params
:
{
account
:
this
.
libraryUsername
}}).
then
((
response
)
=>
{
self
.
result
=
response
.
data
self
.
result
.
display_name
=
self
.
libraryUsername
self
.
isLoading
=
false
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment