2022-11-22 18:06:19 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import tomli
|
|
|
|
import pydantic
|
|
|
|
|
|
|
|
DEBUG = True
|
|
|
|
ROOT_DIR = Path().parent.resolve()
|
|
|
|
DB_PATH = ROOT_DIR / "data" / "database.db"
|
|
|
|
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}"
|
|
|
|
_CONFIG_FILE = "config.toml"
|
|
|
|
|
|
|
|
class Config(pydantic.BaseModel):
|
|
|
|
domain: str
|
|
|
|
username: str
|
|
|
|
# admin_password: bytes # TODO
|
|
|
|
name: str
|
|
|
|
summary: str
|
|
|
|
https: bool
|
|
|
|
icon_url: str
|
|
|
|
image_url: str | None = None
|
|
|
|
secret: str
|
|
|
|
debug: bool = False
|
|
|
|
trusted_hosts: list[str] = ["127.0.0.1"]
|
|
|
|
manually_approves_followers: bool = False
|
|
|
|
also_known_as: str | None = None
|
|
|
|
|
|
|
|
hides_followers: bool = False
|
|
|
|
hides_following: bool = False
|
|
|
|
|
|
|
|
inbox_retention_days: int = 15
|
|
|
|
|
|
|
|
def load_config() -> Config:
|
|
|
|
try:
|
|
|
|
return Config.parse_obj(
|
|
|
|
tomli.loads((ROOT_DIR / "data" / _CONFIG_FILE).read_text())
|
|
|
|
)
|
|
|
|
except FileNotFoundError:
|
|
|
|
raise ValueError(
|
|
|
|
f"{_CONFIG_FILE} is missing"
|
|
|
|
)
|
|
|
|
|
|
|
|
CONFIG = load_config()
|
|
|
|
DOMAIN = CONFIG.domain
|
|
|
|
_SCHEME = "https" if CONFIG.https else "http"
|
|
|
|
ID = f"{_SCHEME}://{DOMAIN}"
|
|
|
|
BASE_URL = ID
|
|
|
|
USERNAME = CONFIG.username
|
|
|
|
KEY_PATH = (ROOT_DIR / "data" / "key.pem")
|
2023-03-17 09:49:09 +01:00
|
|
|
|
|
|
|
USER_AGENT = "Fediverse Application/Foxhole-0.0.1"
|
|
|
|
AP_CONTENT_TYPE = "application/activity+json"
|