2024-10-20 15:26:49 -04:00
|
|
|
import toml
|
|
|
|
import os
|
|
|
|
import secrets
|
|
|
|
|
|
|
|
CONFIG_FILE = 'config.toml'
|
|
|
|
|
|
|
|
def load_or_create_config():
|
|
|
|
if not os.path.exists(CONFIG_FILE):
|
|
|
|
admin_password = secrets.token_urlsafe(16)
|
|
|
|
config = {
|
|
|
|
'admin': {
|
|
|
|
'password': admin_password
|
|
|
|
},
|
|
|
|
'directories': {
|
|
|
|
'upload': 'uploads',
|
|
|
|
'thumbnail': 'thumbnails'
|
2024-10-20 15:53:35 -04:00
|
|
|
},
|
|
|
|
'appearance': {
|
2024-10-20 16:22:45 -04:00
|
|
|
'accent_color': '#ff6600'
|
|
|
|
},
|
|
|
|
'server': {
|
|
|
|
'host': '0.0.0.0',
|
|
|
|
'port': 5002
|
2024-10-20 15:26:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
with open(CONFIG_FILE, 'w') as f:
|
|
|
|
toml.dump(config, f)
|
|
|
|
print(f"Generated new config file with admin password: {admin_password}")
|
|
|
|
else:
|
|
|
|
with open(CONFIG_FILE, 'r') as f:
|
|
|
|
config = toml.load(f)
|
|
|
|
return config
|