Skip to content
Snippets Groups Projects
Select Git revision
  • develop default protected
  • 1514-update-channels
  • 1518-update-django-allauth
  • 1515-update-click
  • master
  • 1434-update-pyld
  • heyarne/funkwhale-enhancement/linting
  • 1481
  • profile-menu-redesign
  • update-frontend-dependencies
  • fix-track-table
  • back-option-for-edits
  • album-sliders
  • cherry-pick-31413fe6
  • 1108-remove-jwt-and-switch-to-oauth-for-ui-auth
  • set-sast-config-2
  • set-sast-config-1
  • 1121-download
  • plugins-v3
  • plugins-v2
  • 1.1.2
  • 1.1.1
  • 1.1
  • 1.1-rc2
  • 1.1-rc1
  • 1.0.1
  • 1.0
  • 1.0-rc1
  • 0.21.2
  • 0.21.1
  • 0.21
  • 0.21-rc2
  • 0.21-rc1
  • 0.20.1
  • 0.20.0
  • 0.20.0-rc1
  • 0.19.1
  • 0.19.0
  • 0.19.0-rc2
  • 0.19.0-rc1
40 results

nodeinfo.py

Blame
  • Forked from funkwhale / funkwhale
    6117 commits behind the upstream repository.
    nodeinfo.py 2.00 KiB
    import memoize.djangocache
    
    import funkwhale_api
    from funkwhale_api.common import preferences
    
    from . import stats
    
    store = memoize.djangocache.Cache("default")
    memo = memoize.Memoizer(store, namespace="instance:stats")
    
    
    def get():
        share_stats = preferences.get("instance__nodeinfo_stats_enabled")
        data = {
            "version": "2.0",
            "software": {"name": "funkwhale", "version": funkwhale_api.__version__},
            "protocols": ["activitypub"],
            "services": {"inbound": [], "outbound": []},
            "openRegistrations": preferences.get("users__registration_enabled"),
            "usage": {"users": {"total": 0}},
            "metadata": {
                "private": preferences.get("instance__nodeinfo_private"),
                "shortDescription": preferences.get("instance__short_description"),
                "longDescription": preferences.get("instance__long_description"),
                "nodeName": preferences.get("instance__name"),
                "library": {
                    "federationEnabled": preferences.get("federation__enabled"),
                    "federationNeedsApproval": preferences.get(
                        "federation__music_needs_approval"
                    ),
                    "anonymousCanListen": not preferences.get(
                        "common__api_authentication_required"
                    ),
                },
            },
        }
        if share_stats:
            getter = memo(lambda: stats.get(), max_age=600)
            statistics = getter()
            data["usage"]["users"]["total"] = statistics["users"]
            data["metadata"]["library"]["tracks"] = {"total": statistics["tracks"]}
            data["metadata"]["library"]["artists"] = {"total": statistics["artists"]}
            data["metadata"]["library"]["albums"] = {"total": statistics["albums"]}
            data["metadata"]["library"]["music"] = {"hours": statistics["music_duration"]}
    
            data["metadata"]["usage"] = {
                "favorites": {"tracks": {"total": statistics["track_favorites"]}},
                "listenings": {"total": statistics["listenings"]},
            }
        return data