Added ability to save/load configs by name
- New PUT method for config allows changing config with specified name - New methods in js controller to handle loading/saving of configs
This commit is contained in:
parent
9f435bf8fe
commit
8fa87c0d1f
|
@ -150,16 +150,28 @@ def search():
|
||||||
mobile=g.user_request.mobile) if 'isch' not in search_util.search_type else '')
|
mobile=g.user_request.mobile) if 'isch' not in search_util.search_type else '')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/config', methods=['GET', 'POST'])
|
@app.route('/config', methods=['GET', 'POST', 'PUT'])
|
||||||
@auth_required
|
@auth_required
|
||||||
def config():
|
def config():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return json.dumps(g.user_config.__dict__)
|
return json.dumps(g.user_config.__dict__)
|
||||||
|
elif request.method == 'PUT':
|
||||||
|
if 'name' in request.args:
|
||||||
|
config_path = os.path.join(app.config['CONFIG_PATH'], request.args.get('name'))
|
||||||
|
session['config'] = json.load(open(config_path)) if os.path.exists(config_path) else session['config']
|
||||||
|
return json.dumps(session['config'])
|
||||||
|
else:
|
||||||
|
return json.dumps({})
|
||||||
else:
|
else:
|
||||||
config_data = request.form.to_dict()
|
config_data = request.form.to_dict()
|
||||||
if 'url' not in config_data or not config_data['url']:
|
if 'url' not in config_data or not config_data['url']:
|
||||||
config_data['url'] = g.user_config.url
|
config_data['url'] = g.user_config.url
|
||||||
|
|
||||||
|
if 'name' in request.args:
|
||||||
|
with open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'w') as config_file:
|
||||||
|
config_file.write(json.dumps(config_data, indent=4))
|
||||||
|
config_file.close()
|
||||||
|
|
||||||
session['config'] = config_data
|
session['config'] = config_data
|
||||||
return redirect(config_data['url'])
|
return redirect(config_data['url'])
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,41 @@ const setupConfigLayout = () => {
|
||||||
fillConfigValues();
|
fillConfigValues();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadConfig = event => {
|
||||||
|
event.preventDefault();
|
||||||
|
let config = prompt("Enter name of config:");
|
||||||
|
if (!config) {
|
||||||
|
alert("Must specify a name for the config to load");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let xhrPUT = new XMLHttpRequest();
|
||||||
|
xhrPUT.open("PUT", "/config?name=" + config + '.json');
|
||||||
|
xhrPUT.onload = function() {
|
||||||
|
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
||||||
|
alert("Error loading Whoogle config");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
location.reload(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
xhrPUT.send();
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveConfig = event => {
|
||||||
|
event.preventDefault();
|
||||||
|
let config = prompt("Enter name for this config:");
|
||||||
|
if (!config) {
|
||||||
|
alert("Must specify a name for the config to save");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let configForm = document.getElementById("config-form");
|
||||||
|
configForm.action = '/config?name=' + config + '.json';
|
||||||
|
configForm.submit();
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
document.getElementById("main").style.display = "block";
|
document.getElementById("main").style.display = "block";
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
<button id="config-collapsible" class="collapsible">Configuration</button>
|
<button id="config-collapsible" class="collapsible">Configuration</button>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="config-fields">
|
<div class="config-fields">
|
||||||
<form action="/config" method="post">
|
<form id="config-form" action="/config" method="post">
|
||||||
<div class="config-div">
|
<div class="config-div">
|
||||||
<!-- TODO: Add option to regenerate user agent? -->
|
<!-- TODO: Add option to regenerate user agent? -->
|
||||||
<span class="ua-span">User Agent: {{ ua }}</span>
|
<span class="ua-span">User Agent: {{ ua }}</span>
|
||||||
|
@ -100,7 +100,9 @@
|
||||||
<input type="text" name="url" id="config-url" value="">
|
<input type="text" name="url" id="config-url" value="">
|
||||||
</div>
|
</div>
|
||||||
<div class="config-div">
|
<div class="config-div">
|
||||||
<input type="submit" id="config-submit" value="Save">
|
<input type="submit" id="config-load" onclick="loadConfig(event)" value="Load">
|
||||||
|
<input type="submit" id="config-submit" value="Apply">
|
||||||
|
<input type="submit" id="config-submit" onclick="saveConfig(event)" value="Save Config">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user