Skip to content
Snippets Groups Projects
common.py 45.5 KiB
Newer Older
  • Learn to ignore specific revisions
  •         "description": "JWT token creation",
        },
        "jwt-refresh": {
            "rate": THROTTLING_USER_RATES.get("jwt-refresh", "30/hour"),
            "description": "JWT token refresh",
        },
        "signup": {
            "rate": THROTTLING_USER_RATES.get("signup", "10/day"),
            "description": "Account creation",
        },
        "verify-email": {
            "rate": THROTTLING_USER_RATES.get("verify-email", "20/h"),
            "description": "Email address confirmation",
        },
        "password-change": {
            "rate": THROTTLING_USER_RATES.get("password-change", "20/h"),
            "description": "Password change (when authenticated)",
        },
        "password-reset": {
            "rate": THROTTLING_USER_RATES.get("password-reset", "20/h"),
            "description": "Password reset request",
        },
        "password-reset-confirm": {
            "rate": THROTTLING_USER_RATES.get("password-reset-confirm", "20/h"),
            "description": "Password reset confirmation",
        },
    
        "fetch": {
            "rate": THROTTLING_USER_RATES.get("fetch", "200/d"),
            "description": "Fetch remote objects",
        },
    
    Agate's avatar
    Agate committed
    THROTTLING_RATES = THROTTLING_RATES
    """
    Throttling rates for specific endpoints and features of the app. You can tweak this if you are
    encountering to severe rate limiting issues or, on the contrary, if you want to reduce
    the consumption on some endpoints.
    
    Agate's avatar
    Agate committed
    Example:
    
    - ``signup=5/d,password-reset=2/d,anonymous-reports=5/d``
    """
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    BROWSABLE_API_ENABLED = env.bool("BROWSABLE_API_ENABLED", default=False)
    
    if BROWSABLE_API_ENABLED:
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"] += (
            "rest_framework.renderers.BrowsableAPIRenderer",
    
    REST_AUTH_SERIALIZERS = {
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "PASSWORD_RESET_SERIALIZER": "funkwhale_api.users.serializers.PasswordResetSerializer"  # noqa
    
    }
    REST_SESSION_LOGIN = False
    REST_USE_JWT = True
    
    USE_X_FORWARDED_HOST = True
    USE_X_FORWARDED_PORT = True
    
    
    # Wether we should use Apache, Nginx (or other) headers when serving audio files
    # Default to Nginx
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    REVERSE_PROXY_TYPE = env("REVERSE_PROXY_TYPE", default="nginx")
    
    Agate's avatar
    Agate committed
    """
    Depending on the reverse proxy used in front of your funkwhale instance,
    the API will use different kind of headers to serve audio files
    
    Allowed values: ``nginx``, ``apache2``
    """
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    assert REVERSE_PROXY_TYPE in ["apache2", "nginx"], "Unsupported REVERSE_PROXY_TYPE"
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    PROTECT_FILES_PATH = env("PROTECT_FILES_PATH", default="/_protected")
    
    Agate's avatar
    Agate committed
    """
    Which path will be used to process the internal redirection to the reverse proxy
    **DO NOT** put a slash at the end.
    
    Agate's avatar
    Agate committed
    You shouldn't have to tweak this.
    """
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    MUSICBRAINZ_CACHE_DURATION = env.int("MUSICBRAINZ_CACHE_DURATION", default=300)
    
    Agate's avatar
    Agate committed
    """
    How long to cache MusicBrainz results, in seconds
    """
    
    MUSICBRAINZ_HOSTNAME = env("MUSICBRAINZ_HOSTNAME", default="musicbrainz.org")
    
    Agate's avatar
    Agate committed
    """
    Use this setting to change the musicbrainz hostname, for instance to
    use a mirror. The hostname can also contain a port number.
    
    Agate's avatar
    Agate committed
    Example:
    
    - ``mymusicbrainz.mirror``
    - ``localhost:5000``
    
    """
    
    # Custom Admin URL, use {% url 'admin:index' %}
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    ADMIN_URL = env("DJANGO_ADMIN_URL", default="^api/admin/")
    
    Agate's avatar
    Agate committed
    """
    Path to the Django admin area.
    
    Exemples:
    
    - `^api/admin/`
    - `^api/mycustompath/`
    
    """
    
    CSRF_USE_SESSIONS = True
    
    SESSION_ENGINE = "django.contrib.sessions.backends.cache"
    
    
    # Playlist settings
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    PLAYLISTS_MAX_TRACKS = env.int("PLAYLISTS_MAX_TRACKS", default=250)
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "funkwhale",
        "library",
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "test",
        "status",
        "root",
        "admin",
        "owner",
        "superuser",
        "staff",
        "service",
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "-",
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "inbox",
        "outbox",
        "shared-inbox",
        "shared_inbox",
        "actor",
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    ] + env.list("ACCOUNT_USERNAME_BLACKLIST", default=[])
    
    Agate's avatar
    Agate committed
    """
    List of usernames that will be unavailable during registration.
    """
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    EXTERNAL_REQUESTS_VERIFY_SSL = env.bool("EXTERNAL_REQUESTS_VERIFY_SSL", default=True)
    
    Agate's avatar
    Agate committed
    """
    Wether to enforce HTTPS certificates verification when doing outgoing HTTP requests (typically with federation).
    Disabling this is not recommended.
    """
    
    EXTERNAL_REQUESTS_TIMEOUT = env.int("EXTERNAL_REQUESTS_TIMEOUT", default=10)
    
    Agate's avatar
    Agate committed
    """
    Default timeout for external requests.
    """
    
    # XXX: deprecated, see #186
    API_AUTHENTICATION_REQUIRED = env.bool("API_AUTHENTICATION_REQUIRED", True)
    
    Eliot Berriot's avatar
    Eliot Berriot committed
    MUSIC_DIRECTORY_PATH = env("MUSIC_DIRECTORY_PATH", default=None)
    
    Agate's avatar
    Agate committed
    """
    The path on your server where Funkwhale can import files using :ref:`in-place import
    <in-place-import>`. It must be readable by the webserver and Funkwhale
    api and worker processes.
    
    On docker installations, we recommend you use the default of ``/music``
    for this value. For non-docker installation, you can use any absolute path.
    ``/srv/funkwhale/data/music`` is a safe choice if you don't know what to use.
    
    .. note:: This path should not include any trailing slash
    
    .. warning::
    
       You need to adapt your :ref:`reverse-proxy configuration<reverse-proxy-setup>` to
       serve the directory pointed by ``MUSIC_DIRECTORY_PATH`` on
       ``/_protected/music`` URL.
    
    """
    
    MUSIC_DIRECTORY_SERVE_PATH = env(
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        "MUSIC_DIRECTORY_SERVE_PATH", default=MUSIC_DIRECTORY_PATH
    )
    
    Agate's avatar
    Agate committed
    """
    Default: :attr:`MUSIC_DIRECTORY_PATH`
    
    When using Docker, the value of :attr:`MUSIC_DIRECTORY_PATH` in your containers
    may differ from the real path on your host. Assuming you have the following directive
    in your :file:`docker-compose.yml` file::
    
        volumes:
          - /srv/funkwhale/data/music:/music:ro
    
    Then, the value of :attr:`MUSIC_DIRECTORY_SERVE_PATH` should be
    ``/srv/funkwhale/data/music``. This must be readable by the webserver.
    
    On non-docker setup, you don't need to configure this setting.
    
    .. note:: This path should not include any trailing slash
    
    """
    
    # When this is set to default=True, we need to reenable migration music/0042
    # to ensure data is populated correctly on existing pods
    MUSIC_USE_DENORMALIZATION = env.bool("MUSIC_USE_DENORMALIZATION", default=False)
    
    USERS_INVITATION_EXPIRATION_DAYS = env.int(
        "USERS_INVITATION_EXPIRATION_DAYS", default=14
    )
    
    Agate's avatar
    Agate committed
    """
    Expiration delay in days, for user invitations.
    """
    
    
    VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
        "square": [
            ("original", "url"),
            ("square_crop", "crop__400x400"),
            ("medium_square_crop", "crop__200x200"),
            ("small_square_crop", "crop__50x50"),
    
    Eliot Berriot's avatar
    Eliot Berriot committed
        ],
        "attachment_square": [
            ("original", "url"),
            ("medium_square_crop", "crop__200x200"),
        ],
    
    }
    VERSATILEIMAGEFIELD_SETTINGS = {"create_images_on_demand": False}
    
    RSA_KEY_SIZE = 2048
    # for performance gain in tests, since we don't need to actually create the
    # thumbnails
    CREATE_IMAGE_THUMBNAILS = env.bool("CREATE_IMAGE_THUMBNAILS", default=True)
    
    # we rotate actor keys at most every two days by default
    ACTOR_KEY_ROTATION_DELAY = env.int("ACTOR_KEY_ROTATION_DELAY", default=3600 * 48)
    
    SUBSONIC_DEFAULT_TRANSCODING_FORMAT = (
        env("SUBSONIC_DEFAULT_TRANSCODING_FORMAT", default="mp3") or None
    )
    
    Agate's avatar
    Agate committed
    """
    Default format for transcoding when using Subsonic API.
    """
    
    # extra tags will be ignored
    TAGS_MAX_BY_OBJ = env.int("TAGS_MAX_BY_OBJ", default=30)
    
    Agate's avatar
    Agate committed
    """
    Maximum number of tags that can be associated with an object. Extra tags will be ignored.
    """
    
    FEDERATION_OBJECT_FETCH_DELAY = env.int(
        "FEDERATION_OBJECT_FETCH_DELAY", default=60 * 24 * 3
    )
    
    Agate's avatar
    Agate committed
    """
    Number of minutes before a remote object will be automatically refetched when accessed in the UI.
    """
    
    MODERATION_EMAIL_NOTIFICATIONS_ENABLED = env.bool(
        "MODERATION_EMAIL_NOTIFICATIONS_ENABLED", default=True
    )
    
    Agate's avatar
    Agate committed
    """
    Whether to enable email notifications to moderators and pods admins.
    """
    
    FEDERATION_AUTHENTIFY_FETCHES = True
    FEDERATION_SYNCHRONOUS_FETCH = env.bool("FEDERATION_SYNCHRONOUS_FETCH", default=True)
    FEDERATION_DUPLICATE_FETCH_DELAY = env.int(
        "FEDERATION_DUPLICATE_FETCH_DELAY", default=60 * 50
    )
    
    Agate's avatar
    Agate committed
    """
    Delay, in seconds, between two manual fetch of the same remote object.
    """
    
    INSTANCE_SUPPORT_MESSAGE_DELAY = env.int("INSTANCE_SUPPORT_MESSAGE_DELAY", default=15)
    
    Agate's avatar
    Agate committed
    """
    Delay in days after signup before we show the "support your pod" message
    """
    
    FUNKWHALE_SUPPORT_MESSAGE_DELAY = env.int("FUNKWHALE_SUPPORT_MESSAGE_DELAY", default=15)
    
    Agate's avatar
    Agate committed
    """
    Delay in days after signup before we show the "support Funkwhale" message
    """
    
    # XXX Stable release: remove
    USE_FULL_TEXT_SEARCH = env.bool("USE_FULL_TEXT_SEARCH", default=True)
    
    
    MIN_DELAY_BETWEEN_DOWNLOADS_COUNT = env.int(
        "MIN_DELAY_BETWEEN_DOWNLOADS_COUNT", default=60 * 60 * 6
    )
    
    Agate's avatar
    Agate committed
    """
    Minimum required period, in seconds, for two downloads of the same track by the same IP
    or user to be recorded in statistics.
    """
    
    MARKDOWN_EXTENSIONS = env.list("MARKDOWN_EXTENSIONS", default=["nl2br", "extra"])
    
    Agate's avatar
    Agate committed
    """
    List of markdown extensions to enable.
    
    Agate's avatar
    Agate committed
    Cf `<https://python-markdown.github.io/extensions/>`_
    """
    
    LINKIFIER_SUPPORTED_TLDS = ["audio"] + env.list("LINKINFIER_SUPPORTED_TLDS", default=[])
    
    Agate's avatar
    Agate committed
    """
    Additional TLDs to support with our markdown linkifier.
    """
    
    EXTERNAL_MEDIA_PROXY_ENABLED = env.bool("EXTERNAL_MEDIA_PROXY_ENABLED", default=True)
    
    Agate's avatar
    Agate committed
    """
    Wether to proxy attachment files hosted on third party pods and and servers. Keeping
    this to true is recommended, to reduce leaking browsing information of your users, and
    reduce the bandwidth used on remote pods.
    """
    
    PODCASTS_THIRD_PARTY_VISIBILITY = env("PODCASTS_THIRD_PARTY_VISIBILITY", default="me")
    
    Agate's avatar
    Agate committed
    """
    By default, only people who subscribe to a podcast RSS will have access to their episodes.
    switch to "instance" or "everyone" to change that.
    
    Changing it only affect new podcasts.
    """
    
    PODCASTS_RSS_FEED_REFRESH_DELAY = env.int(
        "PODCASTS_RSS_FEED_REFRESH_DELAY", default=60 * 60 * 24
    )
    
    Agate's avatar
    Agate committed
    """
    Delay in seconds between to fetch of RSS feeds. Reducing this mean you'll receive new episodes faster,
    but will require more resources.
    """
    
    # maximum items loaded through XML feed
    PODCASTS_RSS_FEED_MAX_ITEMS = env.int("PODCASTS_RSS_FEED_MAX_ITEMS", default=250)
    
    Agate's avatar
    Agate committed
    """
    Maximum number of RSS items to load in each podcast feed.
    """
    
    
    IGNORE_FORWARDED_HOST_AND_PROTO = env.bool(
        "IGNORE_FORWARDED_HOST_AND_PROTO", default=True
    )
    """
    Use :attr:`FUNKWHALE_HOSTNAME` and :attr:`FUNKWHALE_PROTOCOL ` instead of request header.
    """