mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-12-22 11:11:09 +00:00
Fix db wipe on json error and default config checking
This commit is contained in:
parent
f3b4fc44b8
commit
b4f0835106
|
@ -9,7 +9,23 @@ import yaml
|
|||
|
||||
def load_config():
|
||||
with open('relay.yaml') as f:
|
||||
return yaml.load(f)
|
||||
yaml_file = yaml.load(f)
|
||||
whitelist = yaml_file['ap'].get('whitelist', [])
|
||||
blocked = yaml_file['ap'].get('blocked_instances', [])
|
||||
|
||||
config = {
|
||||
'db': yaml_file.get('db', 'relay.jsonld'),
|
||||
'listen': yaml_file.get('listen', '0.0.0.0'),
|
||||
'port': int(yaml_file.get('port', 8080)),
|
||||
'note': yaml_file.get('note', 'Make a note about your instance here.'),
|
||||
'ap': {
|
||||
'blocked_instances': [] if blocked is None else blocked,
|
||||
'host': yaml_file['ap'].get('host', 'localhost'),
|
||||
'whitelist': [] if whitelist is None else whitelist,
|
||||
'whitelist_enabled': yaml_file['ap'].get('whitelist_enabled', False)
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
||||
|
||||
CONFIG = load_config()
|
||||
|
|
|
@ -36,7 +36,7 @@ from . import app, CONFIG
|
|||
from .remote_actor import fetch_actor
|
||||
|
||||
|
||||
AP_CONFIG = CONFIG.get('ap', {'host': 'localhost','blocked_instances':[], 'whitelist_enabled': False, 'whitelist': []})
|
||||
AP_CONFIG = CONFIG['ap']
|
||||
CACHE_SIZE = CONFIG.get('cache-size', 16384)
|
||||
|
||||
|
||||
|
|
|
@ -2,19 +2,24 @@ import asyncio
|
|||
import logging
|
||||
import urllib.parse
|
||||
import simplejson as json
|
||||
from sys import exit
|
||||
|
||||
|
||||
from . import CONFIG
|
||||
AP_CONFIG = CONFIG.get('ap', {'blocked_instances':[], 'whitelist_enabled': False, 'whitelist': []})
|
||||
|
||||
AP_CONFIG = CONFIG['ap']
|
||||
|
||||
try:
|
||||
with open(CONFIG['db']) as f:
|
||||
DATABASE = json.load(f)
|
||||
except:
|
||||
|
||||
except FileNotFoundError:
|
||||
logging.info('No database was found, making a new one.')
|
||||
DATABASE = {}
|
||||
|
||||
except json.decoder.JSONDecodeError:
|
||||
logging.info('Invalid JSON in db. Exiting...')
|
||||
exit(1)
|
||||
|
||||
following = DATABASE.get('relay-list', [])
|
||||
for inbox in following:
|
||||
if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']:
|
||||
|
|
Loading…
Reference in a new issue