Some improvements and modifications related to the issue #25
This commit is contained in:
@ -9,6 +9,7 @@ import sys
|
||||
config_bp = Blueprint("config", __name__)
|
||||
config = Config()
|
||||
|
||||
|
||||
@config_bp.route('/switch/<cat>/<key>', methods=['GET'])
|
||||
@require_header_token
|
||||
def switch(cat, key):
|
||||
@ -18,20 +19,21 @@ def switch(cat, key):
|
||||
"""
|
||||
try:
|
||||
value = config.read_config((cat, key))
|
||||
if value:
|
||||
if value:
|
||||
config.write_config(cat, key, False)
|
||||
res = { "status" : True,
|
||||
"message" : "Key switched to false" }
|
||||
res = {"status": True,
|
||||
"message": "Key switched to false"}
|
||||
else:
|
||||
config.write_config(cat, key, True)
|
||||
res = { "status" : True,
|
||||
"message" : "Key switched to true" }
|
||||
res = {"status": True,
|
||||
"message": "Key switched to true"}
|
||||
except:
|
||||
res = { "status" : True,
|
||||
"message" : "Issue while changing value" }
|
||||
|
||||
res = {"status": True,
|
||||
"message": "Issue while changing value"}
|
||||
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@config_bp.route('/edit/<cat>/<key>/<path:value>', methods=['GET'])
|
||||
@require_header_token
|
||||
def edit(cat, key, value):
|
||||
@ -39,15 +41,8 @@ def edit(cat, key, value):
|
||||
Edit the string (or array) value of a configuration key.
|
||||
:return: status in JSON
|
||||
"""
|
||||
value = value.split("|") if "|" in value else value
|
||||
if config.write_config(cat, key, value):
|
||||
res = { "status" : True,
|
||||
"message" : "Configuration updated" }
|
||||
else:
|
||||
res = { "status" : False,
|
||||
"message" : "Can't edit this configuration key" }
|
||||
|
||||
return jsonify(res)
|
||||
return jsonify(config.write_config(cat, key, value))
|
||||
|
||||
|
||||
@config_bp.route('/db/export', methods=['GET'])
|
||||
@require_get_token
|
||||
@ -58,6 +53,7 @@ def export_db():
|
||||
"""
|
||||
return config.export_db()
|
||||
|
||||
|
||||
@config_bp.route('/db/import', methods=['POST'])
|
||||
@require_header_token
|
||||
def import_db():
|
||||
@ -70,13 +66,14 @@ def import_db():
|
||||
assert f.read(15) == b"SQLite format 3"
|
||||
d = "/".join(sys.path[0].split("/")[:-2])
|
||||
f.save("/{}/tinycheck.sqlite3".format(d))
|
||||
res = { "status" : True,
|
||||
"message" : "Database updated" }
|
||||
res = {"status": True,
|
||||
"message": "Database updated"}
|
||||
except:
|
||||
res = { "status" : False,
|
||||
"message" : "Error while database upload" }
|
||||
res = {"status": False,
|
||||
"message": "Error while database upload"}
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
|
||||
@config_bp.route('/list', methods=['GET'])
|
||||
def list():
|
||||
"""
|
||||
@ -85,4 +82,4 @@ def list():
|
||||
"""
|
||||
res = config.export_config()
|
||||
res["backend"]["password"] = ""
|
||||
return jsonify(res)
|
||||
return jsonify(res)
|
||||
|
Reference in New Issue
Block a user