Decided to keep python based, added S3 support
This commit is contained in:
parent
c7586d1aa1
commit
c752138fb0
9 changed files with 293 additions and 37 deletions
21
config.py
21
config.py
|
@ -1,4 +1,8 @@
|
|||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
@ -6,10 +10,23 @@ class Config:
|
|||
SECRET_KEY = os.environ.get('SECRET_KEY', 'your-secret-key')
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', 'sqlite:///' + os.path.join(BASE_DIR, 'instance', 'app.db'))
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'static', 'uploads')
|
||||
|
||||
# Storage configuration
|
||||
STORAGE_URL = os.environ.get('STORAGE_URL', 'file://' + os.path.join(BASE_DIR, 'static', 'uploads'))
|
||||
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'static', 'uploads') # Kept for backwards compatibility
|
||||
|
||||
# S3 Configuration (optional)
|
||||
S3_ACCESS_KEY = os.environ.get('S3_ACCESS_KEY')
|
||||
S3_SECRET_KEY = os.environ.get('S3_SECRET_KEY')
|
||||
S3_ENDPOINT_URL = os.environ.get('S3_ENDPOINT_URL')
|
||||
S3_PUBLIC_URL = os.environ.get('S3_PUBLIC_URL')
|
||||
|
||||
@staticmethod
|
||||
def init_app(app):
|
||||
# Create necessary directories
|
||||
os.makedirs(os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '')), exist_ok=True)
|
||||
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
||||
|
||||
# Only create upload folder if using local storage
|
||||
if app.config['STORAGE_URL'].startswith('file://'):
|
||||
storage_path = app.config['STORAGE_URL'].replace('file://', '')
|
||||
os.makedirs(storage_path, exist_ok=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue