mirror of
https://github.com/hrfee/jellyfin-accounts.git
synced 2024-12-22 17:10:11 +00:00
added new /getConfig
This commit is contained in:
parent
55d26b541a
commit
52f9b5c963
@ -44,6 +44,7 @@ else:
|
||||
data_dir = Path.home() / ".jf-accounts"
|
||||
|
||||
local_dir = (Path(__file__).parent / "data").resolve()
|
||||
config_base_path = local_dir / "config-base.json"
|
||||
|
||||
first_run = False
|
||||
if data_dir.exists() is False or (data_dir / "config.ini").exists() is False:
|
||||
@ -53,8 +54,9 @@ if data_dir.exists() is False or (data_dir / "config.ini").exists() is False:
|
||||
if args.config is None:
|
||||
config_path = data_dir / "config.ini"
|
||||
from jellyfin_accounts.generate_ini import generate_ini
|
||||
|
||||
default_path = local_dir / "config-default.ini"
|
||||
generate_ini(local_dir / "config-base.json", default_path)
|
||||
generate_ini(config_base_path, default_path)
|
||||
shutil.copy(str(default_path), str(config_path))
|
||||
print("Setup through the web UI, or quit and edit the configuration manually.")
|
||||
first_run = True
|
||||
@ -213,6 +215,7 @@ def resp(success=True, code=500):
|
||||
r.status_code = code
|
||||
return r
|
||||
|
||||
|
||||
def main():
|
||||
if args.get_defaults:
|
||||
import json
|
||||
@ -306,6 +309,7 @@ def main():
|
||||
app = Flask(__name__, root_path=str(local_dir))
|
||||
app.config["DEBUG"] = config.getboolean("ui", "debug")
|
||||
app.config["SECRET_KEY"] = secrets.token_urlsafe(16)
|
||||
app.config["JSON_SORT_KEYS"] = False
|
||||
|
||||
from waitress import serve
|
||||
|
||||
|
@ -2,11 +2,12 @@ import configparser
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def generate_ini(base_file, ini_file):
|
||||
"""
|
||||
Generates .ini file from config-base file.
|
||||
"""
|
||||
with open(Path(base_file), 'r') as f:
|
||||
with open(Path(base_file), "r") as f:
|
||||
config_base = json.load(f)
|
||||
|
||||
ini = configparser.RawConfigParser(allow_no_value=True)
|
||||
@ -14,19 +15,16 @@ def generate_ini(base_file, ini_file):
|
||||
for section in config_base:
|
||||
ini.add_section(section)
|
||||
for entry in config_base[section]:
|
||||
if 'description' in config_base[section][entry]:
|
||||
ini.set(section,
|
||||
'; ' + config_base[section][entry]['description'])
|
||||
if entry != 'meta':
|
||||
value = config_base[section][entry]['value']
|
||||
if "description" in config_base[section][entry]:
|
||||
ini.set(section, "; " + config_base[section][entry]["description"])
|
||||
if entry != "meta":
|
||||
value = config_base[section][entry]["value"]
|
||||
if isinstance(value, bool):
|
||||
value = str(value).lower()
|
||||
else:
|
||||
value = str(value)
|
||||
ini.set(section,
|
||||
entry,
|
||||
value)
|
||||
ini.set(section, entry, value)
|
||||
|
||||
with open(Path(ini_file), 'w') as config_file:
|
||||
with open(Path(ini_file), "w") as config_file:
|
||||
ini.write(config_file)
|
||||
return True
|
||||
|
@ -4,7 +4,16 @@ import json
|
||||
import datetime
|
||||
import secrets
|
||||
import time
|
||||
from jellyfin_accounts import config, config_path, app, g, data_store, resp, configparser
|
||||
from jellyfin_accounts import (
|
||||
config,
|
||||
config_path,
|
||||
app,
|
||||
g,
|
||||
data_store,
|
||||
resp,
|
||||
configparser,
|
||||
config_base_path,
|
||||
)
|
||||
from jellyfin_accounts import web_log as log
|
||||
from jellyfin_accounts.validate_password import PasswordValidator
|
||||
|
||||
@ -314,13 +323,14 @@ def setDefaults():
|
||||
return resp()
|
||||
|
||||
|
||||
|
||||
@app.route("/modifyConfig", methods=["POST"])
|
||||
@auth.login_required
|
||||
def modifyConfig():
|
||||
log.info("Config modification requested")
|
||||
data = request.get_json()
|
||||
temp_config = configparser.RawConfigParser(comment_prefixes="/", allow_no_value=True)
|
||||
temp_config = configparser.RawConfigParser(
|
||||
comment_prefixes="/", allow_no_value=True
|
||||
)
|
||||
temp_config.read(config_path)
|
||||
for section in data:
|
||||
if section in temp_config:
|
||||
@ -340,8 +350,22 @@ def modifyConfig():
|
||||
return resp()
|
||||
|
||||
|
||||
@app.route('/getConfig', methods=["GET"])
|
||||
@auth.login_required
|
||||
# @app.route('/getConfig', methods=["GET"])
|
||||
# @auth.login_required
|
||||
# def getConfig():
|
||||
# log.debug('Config requested')
|
||||
# return jsonify(config._sections), 200
|
||||
|
||||
|
||||
@app.route("/getConfig", methods=["GET"])
|
||||
# @auth.login_required
|
||||
def getConfig():
|
||||
log.debug('Config requested')
|
||||
return jsonify(config._sections), 200
|
||||
with open(config_base_path, "r") as f:
|
||||
config_base = json.load(f)
|
||||
response_config = config_base
|
||||
for section in config_base:
|
||||
for entry in config_base[section]:
|
||||
if entry in config[section]:
|
||||
response_config[section][entry]["value"] = config[section][entry]
|
||||
return jsonify(response_config), 200
|
||||
|
Loading…
Reference in New Issue
Block a user