Modularized JSON storage

user_template and other files are now accessed via JSONStorage, which
has dictionary like attributes for each file which can be used like a
dictionary, without the need to manually read and write the file. This
was done so that other storage types (e.g a database) can be added in
future.
This commit is contained in:
2020-06-14 17:58:18 +01:00
parent 39a27eb762
commit f4f18d41ea
5 changed files with 197 additions and 184 deletions

View File

@@ -1,7 +1,7 @@
import json
from pathlib import Path
from flask import Flask, send_from_directory, render_template
from __main__ import config, app, g, css
from __main__ import config, app, g, css, data_store
from __main__ import web_log as log
from jellyfin_accounts.web_api import checkInvite, validator
@@ -43,16 +43,9 @@ def inviteProxy(path):
if checkInvite(path):
log.info(f'Invite {path} used to request form')
try:
with open(config['files']['invites'], 'r') as f:
invites = json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
invites = {'invites': []}
for invite in invites['invites']:
if invite['code'] == path:
try:
email = invite['email']
except KeyError:
email = ""
email = data_store.invites[path]['email']
except KeyError:
email = ''
return render_template('form.html',
css_href=css['href'],
css_integrity=css['integrity'],