feat(api): Add NodeInfo 2.1
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2604>
This commit is contained in:
parent
71140d5a9b
commit
a0ae9bbb70
9 changed files with 263 additions and 29 deletions
|
|
@ -59,7 +59,7 @@ class InstanceSettings(generics.GenericAPIView):
|
|||
|
||||
|
||||
@method_decorator(ensure_csrf_cookie, name="dispatch")
|
||||
class NodeInfo(views.APIView):
|
||||
class NodeInfo20(views.APIView):
|
||||
permission_classes = []
|
||||
authentication_classes = []
|
||||
serializer_class = serializers.NodeInfo20Serializer
|
||||
|
|
@ -122,6 +122,61 @@ class NodeInfo(views.APIView):
|
|||
)
|
||||
|
||||
|
||||
class NodeInfo21(NodeInfo20):
|
||||
serializer_class = serializers.NodeInfo21Serializer
|
||||
|
||||
@extend_schema(
|
||||
responses=serializers.NodeInfo20Serializer, operation_id="getNodeInfo20"
|
||||
)
|
||||
def get(self, request):
|
||||
pref = preferences.all()
|
||||
if (
|
||||
pref["moderation__allow_list_public"]
|
||||
and pref["moderation__allow_list_enabled"]
|
||||
):
|
||||
allowed_domains = list(
|
||||
Domain.objects.filter(allowed=True)
|
||||
.order_by("name")
|
||||
.values_list("name", flat=True)
|
||||
)
|
||||
else:
|
||||
allowed_domains = None
|
||||
|
||||
data = {
|
||||
"software": {"version": funkwhale_version},
|
||||
"services": {"inbound": ["atom1.0"], "outbound": ["atom1.0"]},
|
||||
"preferences": pref,
|
||||
"stats": cache_memoize(600, prefix="memoize:instance:stats")(stats.get)()
|
||||
if pref["instance__nodeinfo_stats_enabled"]
|
||||
else None,
|
||||
"actorId": get_service_actor().fid,
|
||||
"supportedUploadExtensions": SUPPORTED_EXTENSIONS,
|
||||
"allowed_domains": allowed_domains,
|
||||
"languages": pref.get("moderation__languages"),
|
||||
"location": pref.get("instance__location"),
|
||||
"content": cache_memoize(600, prefix="memoize:instance:content")(
|
||||
stats.get_content
|
||||
)()
|
||||
if pref["instance__nodeinfo_stats_enabled"]
|
||||
else None,
|
||||
"features": [
|
||||
"channels",
|
||||
"podcasts",
|
||||
],
|
||||
}
|
||||
|
||||
if not pref.get("common__api_authentication_required"):
|
||||
data["features"].append("anonymousCanListen")
|
||||
|
||||
if pref.get("federation__enabled"):
|
||||
data["features"].append("federation")
|
||||
|
||||
serializer = self.serializer_class(data)
|
||||
return Response(
|
||||
serializer.data, status=200, content_type=NODEINFO_2_CONTENT_TYPE
|
||||
)
|
||||
|
||||
|
||||
PWA_MANIFEST_PATH = Path(__file__).parent / "pwa-manifest.json"
|
||||
PWA_MANIFEST: dict = json.loads(PWA_MANIFEST_PATH.read_text(encoding="utf-8"))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue