Expose external accounts as virtual Org Social feeds that any client
can follow with a plain #+FOLLOW: line:
- /bridge/activitypub/@{user}@{instance}/ bridges a Mastodon or any
ActivityPub account (WebFinger, actor and paginated outbox; only
public top-level notes, with CW, hashtags, language and attachments)
- /bridge/rss/?url={feed} bridges any RSS/Atom feed (entry title as
*** sub-heading, converted body and link to the original article)
Registration is implicit on first GET. Bridged data is stored in the
existing Profile/Post tables so /profile/, /search/ and the rest of
the API work on bridged feeds. Active bridges are refreshed every 15
minutes; bridges unrequested for 90 days are cleaned up.
Remote HTML is converted to Org text, escaping headline-like lines so
external content cannot inject posts. Fetches enforce the Webmention
SSRF protections, a 10s timeout and a 5MB size cap. Bridged posts
never queue Webmentions nor publish notifications.
190 lines
5.5 KiB
Python
190 lines
5.5 KiB
Python
"""
|
|
Django settings for core project.
|
|
|
|
Generated by 'django-admin startproject' using Django 5.2.6.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.environ.get(
|
|
"SECRET_KEY", "django-insecure-y315h5v5t^1c^rqqcpk1y&!7+f8%8rj3$3bh2k!xoco8x@a+kr"
|
|
)
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = os.environ.get("DEBUG", "False").lower() == "true"
|
|
|
|
ALLOWED_HOSTS = os.environ.get(
|
|
"ALLOWED_HOSTS", "localhost,127.0.0.1,django,nginx"
|
|
).split(",")
|
|
|
|
# Site domain configuration
|
|
SITE_DOMAIN = os.environ.get("SITE_DOMAIN", "localhost:8080")
|
|
|
|
# Groups configuration
|
|
# Parse comma-separated groups from environment variable
|
|
# Groups can have spaces and capital letters (e.g., "Emacs,Org Social,Elisp")
|
|
# Slugs are auto-generated (lowercase, spaces become hyphens)
|
|
|
|
|
|
def slugify_group(name):
|
|
"""Convert group name to slug (lowercase, spaces to hyphens)."""
|
|
return name.strip().lower().replace(" ", "-")
|
|
|
|
|
|
GROUPS_ENV = os.environ.get("GROUPS", "")
|
|
if GROUPS_ENV.strip():
|
|
# Parse group names (can have spaces and capitals)
|
|
group_names = [group.strip() for group in GROUPS_ENV.split(",") if group.strip()]
|
|
|
|
# Create mappings between slugs and names
|
|
GROUPS_MAP = {slugify_group(name): name for name in group_names}
|
|
ENABLED_GROUPS = list(GROUPS_MAP.keys()) # List of slugs for backward compatibility
|
|
else:
|
|
GROUPS_MAP = {}
|
|
ENABLED_GROUPS = []
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.contenttypes",
|
|
"rest_framework",
|
|
"django_filters",
|
|
"huey.contrib.djhuey",
|
|
"app.public.apps.PublicConfig",
|
|
"app.feeds.apps.FeedsConfig",
|
|
"app.feedcontent.apps.FeedcontentConfig",
|
|
"app.polls.apps.PollsConfig",
|
|
"app.replies.apps.RepliesConfig",
|
|
"app.mentions.apps.MentionsConfig",
|
|
"app.reactions.apps.ReactionsConfig",
|
|
"app.repliesto.apps.RepliesToConfig",
|
|
"app.notifications.apps.NotificationsConfig",
|
|
"app.search.apps.SearchConfig",
|
|
"app.groups.apps.GroupsConfig",
|
|
"app.rss.apps.RssConfig",
|
|
"app.boosts.apps.BoostsConfig",
|
|
"app.interactions.apps.InteractionsConfig",
|
|
"app.sse_notifications.apps.SseNotificationsConfig",
|
|
"app.profile.apps.ProfileConfig",
|
|
"app.stats.apps.StatsConfig",
|
|
"app.bridge.apps.BridgeConfig",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"app.feeds.cors_middleware.CORSMiddleware", # Add CORS headers to all responses
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"app.feeds.middleware.RelayMetadataMiddleware", # Add global ETag/Last-Modified headers
|
|
]
|
|
|
|
ROOT_URLCONF = "core.urls"
|
|
|
|
TEMPLATES = []
|
|
|
|
WSGI_APPLICATION = "core.wsgi.application"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": BASE_DIR / "db.sqlite3",
|
|
}
|
|
}
|
|
|
|
|
|
# No authentication system needed for this API
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
|
|
TIME_ZONE = "UTC"
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# No static files needed for API-only application
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
# Django REST Framework settings
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_RENDERER_CLASSES": [
|
|
"app.reactions.renderers.UTF8JSONRenderer",
|
|
],
|
|
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
|
|
"PAGE_SIZE": 20,
|
|
"DEFAULT_FILTER_BACKENDS": [
|
|
"rest_framework.filters.SearchFilter",
|
|
"rest_framework.filters.OrderingFilter",
|
|
],
|
|
"DEFAULT_PERMISSION_CLASSES": [
|
|
"rest_framework.permissions.AllowAny",
|
|
],
|
|
"DEFAULT_AUTHENTICATION_CLASSES": [],
|
|
"UNAUTHENTICATED_USER": None,
|
|
"UNAUTHENTICATED_TOKEN": None,
|
|
}
|
|
|
|
# Cache configuration
|
|
# In DEBUG (dev/test) we use DummyCache so the suite runs without Redis.
|
|
# In production we always use Redis: a startup probe is unsafe because if Redis
|
|
# is still warming up at import time the process would silently fall back to
|
|
# DummyCache for its entire lifetime, breaking cache invalidation.
|
|
|
|
if DEBUG:
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
|
}
|
|
}
|
|
else:
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
|
"LOCATION": f"redis://{os.environ.get('REDIS_HOST', 'redis')}:{os.environ.get('REDIS_PORT', 6379)}/{os.environ.get('REDIS_CACHE_DB', 1)}",
|
|
}
|
|
}
|
|
|
|
# Huey configuration for task queue and cron jobs
|
|
HUEY = {
|
|
"huey_class": "huey.RedisHuey",
|
|
"name": "org-social-relay",
|
|
"immediate": False, # Required for consumer to run
|
|
"connection": {
|
|
"host": os.environ.get("REDIS_HOST", "redis"),
|
|
"port": int(os.environ.get("REDIS_PORT", 6379)),
|
|
"db": int(os.environ.get("REDIS_DB", 0)),
|
|
},
|
|
"consumer": {
|
|
"workers": int(os.environ.get("HUEY_WORKERS", 1)),
|
|
"worker_type": "thread",
|
|
},
|
|
}
|