simpliest_fs/config.py

49 lines
1.8 KiB
Python

import os
import yaml
CONFIG = {}
STORAGE_ROOT = ""
DEFAULT_CONFIG = """# config.yaml
server:
host: 127.0.0.1
port: 8000
session_timeout: 3600 # Seconds
use_as_cdn: true # Use as "CDN" or not (show image, play video+audio, load htmls)
security:
api_token: "test" # Change this in production
storage:
root_dir: "./file_storage" # Where store files
default_quota_mb: 100 # Default amount of megabytes to user
ui:
title: "Simple File Server"
contact_email: "del.pw.official@gmail.com"
disclaimer: "NO warranty or liability provided. You are SOLELY responsible for the files you upload. For deletion requests and claims use email on Telegram (prefered)"
disclaimer_ru: "НИКАКИХ гарантий не предоставляется. Вы несете ПОЛНУЮ ответственность за загружаемые вами файлы. Для запросов на удаление и претензий используйте электронную почту или Telegram (предпочтительно)"
register_info: 'RU: Для регистрации необходимо быть участником <a href="https://t.me/justuser31_chat_new">нашего чата</a>, а затем прописать <code>/reg_sfs</code> и следовать инструкции бота.'
logging:
enabled: false
"""
def load_config():
global CONFIG, STORAGE_ROOT
if not os.path.isfile("config.yaml"):
with open("config.yaml", "w") as f:
f.write(DEFAULT_CONFIG)
print("No config found. CREATED NEW config.yaml")
with open("config.yaml", "r") as f:
CONFIG = yaml.safe_load(f)
STORAGE_ROOT = CONFIG["storage"]["root_dir"]
os.makedirs(STORAGE_ROOT, exist_ok=True)
return CONFIG
def get_storage_root():
return STORAGE_ROOT