2023-04-10 15:43:42 +00:00
|
|
|
"""
|
|
|
|
Gallery configuration file
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import platformdirs
|
2023-04-22 13:45:29 +00:00
|
|
|
import importlib.metadata
|
2023-04-10 15:43:42 +00:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from yaml import safe_load
|
2023-09-26 18:36:49 +00:00
|
|
|
from utils import startup
|
|
|
|
|
|
|
|
|
|
|
|
# App Sanity Checks
|
|
|
|
startup.check_dirs()
|
|
|
|
startup.check_env()
|
|
|
|
startup.check_conf()
|
2023-04-10 15:43:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Set dirs
|
2023-09-26 12:43:00 +00:00
|
|
|
APPLICATION_ROOT = platformdirs.user_config_dir("onlylegs")
|
2023-04-10 15:43:42 +00:00
|
|
|
|
|
|
|
# Load environment variables
|
2023-04-20 19:20:58 +00:00
|
|
|
# print("Loading environment variables...")
|
2023-09-26 12:43:00 +00:00
|
|
|
load_dotenv(os.path.join(APPLICATION_ROOT, ".env"))
|
2023-04-10 15:43:42 +00:00
|
|
|
|
|
|
|
# Load config from user dir
|
2023-04-20 19:20:58 +00:00
|
|
|
# print("Loading config...")
|
2023-09-26 12:43:00 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(APPLICATION_ROOT, "conf.yml"), encoding="utf-8", mode="r"
|
|
|
|
) as file:
|
2023-04-10 15:43:42 +00:00
|
|
|
conf = safe_load(file)
|
|
|
|
|
|
|
|
|
|
|
|
# Flask config
|
|
|
|
SECRET_KEY = os.environ.get("FLASK_SECRET")
|
2023-09-26 18:36:49 +00:00
|
|
|
DATABASE_NAME = "gallery.sqlite3"
|
|
|
|
SQLALCHEMY_DATABASE_URI = "sqlite:///" + DATABASE_NAME
|
2023-04-10 15:43:42 +00:00
|
|
|
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
|
2023-09-26 12:43:00 +00:00
|
|
|
UPLOAD_FOLDER = os.path.join(APPLICATION_ROOT, "media", "uploads")
|
|
|
|
CACHE_FOLDER = os.path.join(APPLICATION_ROOT, "media", "cache")
|
|
|
|
PFP_FOLDER = os.path.join(APPLICATION_ROOT, "media", "pfp")
|
|
|
|
MEDIA_FOLDER = os.path.join(APPLICATION_ROOT, "media")
|
2023-04-20 19:20:58 +00:00
|
|
|
|
|
|
|
# Database
|
2023-09-26 12:43:00 +00:00
|
|
|
INSTANCE_DIR = os.path.join(APPLICATION_ROOT, "instance")
|
2023-04-20 19:20:58 +00:00
|
|
|
MIGRATIONS_DIR = os.path.join(INSTANCE_DIR, "migrations")
|
2023-04-22 13:45:29 +00:00
|
|
|
|
|
|
|
# App
|
2023-04-22 14:11:47 +00:00
|
|
|
APP_VERSION = importlib.metadata.version("OnlyLegs")
|