2023-04-10 15:43:42 +00:00
|
|
|
"""
|
|
|
|
Gallery configuration file
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import platformdirs
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from yaml import safe_load
|
|
|
|
|
|
|
|
|
|
|
|
# Set dirs
|
|
|
|
user_dir = platformdirs.user_config_dir("onlylegs")
|
|
|
|
instance_dir = os.path.join(user_dir, "instance")
|
|
|
|
|
|
|
|
# Load environment variables
|
2023-04-20 19:20:58 +00:00
|
|
|
# print("Loading environment variables...")
|
2023-04-10 15:43:42 +00:00
|
|
|
load_dotenv(os.path.join(user_dir, ".env"))
|
|
|
|
|
|
|
|
# Load config from user dir
|
2023-04-20 19:20:58 +00:00
|
|
|
# print("Loading config...")
|
2023-04-10 15:43:42 +00:00
|
|
|
with open(os.path.join(user_dir, "conf.yml"), encoding="utf-8", mode="r") as file:
|
|
|
|
conf = safe_load(file)
|
|
|
|
|
|
|
|
|
|
|
|
# Flask config
|
|
|
|
SECRET_KEY = os.environ.get("FLASK_SECRET")
|
|
|
|
SQLALCHEMY_DATABASE_URI = "sqlite:///gallery.sqlite3"
|
|
|
|
MAX_CONTENT_LENGTH = 1024 * 1024 * conf["upload"]["max-size"]
|
|
|
|
ALLOWED_EXTENSIONS = conf["upload"]["allowed-extensions"]
|
|
|
|
|
|
|
|
# Pass YAML config to app
|
|
|
|
ADMIN_CONF = conf["admin"]
|
|
|
|
UPLOAD_CONF = conf["upload"]
|
|
|
|
WEBSITE_CONF = conf["website"]
|
2023-04-20 19:20:58 +00:00
|
|
|
|
|
|
|
# Directories
|
|
|
|
UPLOAD_FOLDER = os.path.join(user_dir, "media", "uploads")
|
|
|
|
CACHE_FOLDER = os.path.join(user_dir, "media", "cache")
|
|
|
|
PFP_FOLDER = os.path.join(user_dir, "media", "pfp")
|
2023-04-20 20:45:57 +00:00
|
|
|
MEDIA_FOLDER = os.path.join(user_dir, "media")
|
2023-04-20 19:20:58 +00:00
|
|
|
|
|
|
|
# Database
|
|
|
|
INSTANCE_DIR = instance_dir
|
|
|
|
MIGRATIONS_DIR = os.path.join(INSTANCE_DIR, "migrations")
|