155 lines
4.6 KiB
Python
155 lines
4.6 KiB
Python
"""
|
|
Django settings for rfiles.online — standalone file sharing platform.
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
load_dotenv(BASE_DIR / '.env')
|
|
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'django-insecure-rfiles-change-me-in-production')
|
|
DEBUG = os.environ.get('DEBUG', 'True') == 'True'
|
|
ALLOWED_HOSTS = [h.strip() for h in os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1,.rfiles.online').split(',') if h.strip()]
|
|
|
|
# Application definition
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'rest_framework',
|
|
'rest_framework.authtoken',
|
|
'corsheaders',
|
|
'simple_history',
|
|
'files',
|
|
'portal',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
'simple_history.middleware.HistoryRequestMiddleware',
|
|
'config.middleware.HostBasedURLConfMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'config.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'config.wsgi.application'
|
|
|
|
# Database
|
|
import dj_database_url
|
|
DATABASES = {
|
|
'default': dj_database_url.config(
|
|
default=f'sqlite:///{BASE_DIR / "db.sqlite3"}',
|
|
conn_max_age=600,
|
|
)
|
|
}
|
|
|
|
# Password validation
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
|
|
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
|
|
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
|
|
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
|
|
]
|
|
|
|
# Internationalization
|
|
LANGUAGE_CODE = 'en-us'
|
|
TIME_ZONE = 'UTC'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
# Static files
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STORAGES = {
|
|
'default': {
|
|
'BACKEND': 'django.core.files.storage.FileSystemStorage',
|
|
},
|
|
'staticfiles': {
|
|
'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage',
|
|
},
|
|
}
|
|
|
|
# Media files
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = BASE_DIR / 'media'
|
|
|
|
# File upload limits (no limit)
|
|
FILE_UPLOAD_MAX_MEMORY_SIZE = 10737418240 # 10GB
|
|
DATA_UPLOAD_MAX_MEMORY_SIZE = 10737418240 # 10GB
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
# REST Framework
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
],
|
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
|
'PAGE_SIZE': 50,
|
|
}
|
|
|
|
# CORS
|
|
CORS_ALLOWED_ORIGINS = [
|
|
h.strip() for h in os.environ.get('CORS_ALLOWED_ORIGINS', 'http://localhost:3000,http://localhost:8000').split(',') if h.strip()
|
|
]
|
|
CORS_ALLOW_ALL_ORIGINS = DEBUG
|
|
|
|
# Celery
|
|
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379/0')
|
|
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0')
|
|
CELERY_ACCEPT_CONTENT = ['json']
|
|
CELERY_TASK_SERIALIZER = 'json'
|
|
CELERY_RESULT_SERIALIZER = 'json'
|
|
CELERY_TIMEZONE = 'UTC'
|
|
CELERY_BEAT_SCHEDULE = {
|
|
'cleanup-expired-shares': {
|
|
'task': 'files.tasks.cleanup_expired_shares',
|
|
'schedule': 3600, # every hour
|
|
},
|
|
'cleanup-old-access-logs': {
|
|
'task': 'files.tasks.cleanup_old_access_logs',
|
|
'schedule': 86400, # daily
|
|
},
|
|
}
|
|
|
|
# rfiles-specific settings
|
|
SHARE_BASE_URL = os.environ.get('SHARE_BASE_URL', 'https://rfiles.online')
|
|
|
|
# Security (production)
|
|
if not DEBUG:
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
CSRF_TRUSTED_ORIGINS = [
|
|
'https://rfiles.online',
|
|
'https://*.rfiles.online',
|
|
]
|