This commit is contained in:
2026-06-12 14:27:19 +08:00
commit d8dccfc04c
12 changed files with 1796 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import os
from dotenv import load_dotenv
# 加载 .env 文件
load_dotenv(os.path.join(os.path.dirname(__file__), '.env'))
class Config:
"""应用配置(全部从环境变量 / .env 文件读取)"""
# Flask 密钥
SECRET_KEY = os.getenv('SECRET_KEY', 'file-upload-site-secret-key-change-me')
# NAS 文件存储根目录
UPLOAD_ROOT = os.getenv('UPLOAD_ROOT', os.path.join(os.path.dirname(__file__), 'uploads'))
# 单文件大小限制(字节),默认 20MB
MAX_FILE_SIZE = int(os.getenv('MAX_FILE_SIZE', str(20 * 1024 * 1024)))
# 单次最多上传文件数
MAX_FILES_PER_UPLOAD = int(os.getenv('MAX_FILES_PER_UPLOAD', '9'))
# Rate Limiting单 IP 每小时最多上传次数
RATE_LIMIT_PER_HOUR = int(os.getenv('RATE_LIMIT_PER_HOUR', '20'))
# 验证码过期时间(秒)
CAPTCHA_EXPIRY = int(os.getenv('CAPTCHA_EXPIRY', '300'))
# 服务监听端口
PORT = int(os.getenv('PORT', '5000'))
# 是否开启 debug 模式
DEBUG = os.getenv('DEBUG', 'false').lower() in ('true', '1', 'yes')
# 允许的文件 MIME 类型
ALLOWED_MIME_TYPES = {
'text/plain': '.txt',
'application/msword': '.doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
'application/pdf': '.pdf',
'application/rtf': '.rtf',
'text/rtf': '.rtf',
'application/vnd.oasis.opendocument.text': '.odt',
'text/html': '.html',
'text/csv': '.csv',
'application/vnd.ms-excel': '.xls',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',
}