Switched to pickling saved configs
This commit is contained in:
parent
60a1cf24b9
commit
b73579a11d
|
@ -12,6 +12,7 @@ from functools import wraps
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import pickle
|
||||||
import urllib.parse as urlparse
|
import urllib.parse as urlparse
|
||||||
from requests import exceptions
|
from requests import exceptions
|
||||||
import uuid
|
import uuid
|
||||||
|
@ -156,8 +157,8 @@ def config():
|
||||||
return json.dumps(g.user_config.__dict__)
|
return json.dumps(g.user_config.__dict__)
|
||||||
elif request.method == 'PUT':
|
elif request.method == 'PUT':
|
||||||
if 'name' in request.args:
|
if 'name' in request.args:
|
||||||
config_path = os.path.join(app.config['CONFIG_PATH'], request.args.get('name'))
|
config_pkl = 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']
|
session['config'] = pickle.load(open(config_pkl, 'rb')) if os.path.exists(config_pkl) else session['config']
|
||||||
return json.dumps(session['config'])
|
return json.dumps(session['config'])
|
||||||
else:
|
else:
|
||||||
return json.dumps({})
|
return json.dumps({})
|
||||||
|
@ -167,9 +168,7 @@ def config():
|
||||||
config_data['url'] = g.user_config.url
|
config_data['url'] = g.user_config.url
|
||||||
|
|
||||||
if 'name' in request.args:
|
if 'name' in request.args:
|
||||||
with open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'w') as config_file:
|
pickle.dump(config_data, open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'wb'))
|
||||||
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'])
|
||||||
|
|
|
@ -80,7 +80,7 @@ const loadConfig = event => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let xhrPUT = new XMLHttpRequest();
|
let xhrPUT = new XMLHttpRequest();
|
||||||
xhrPUT.open("PUT", "/config?name=" + config + '.json');
|
xhrPUT.open("PUT", "/config?name=" + config);
|
||||||
xhrPUT.onload = function() {
|
xhrPUT.onload = function() {
|
||||||
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
||||||
alert("Error loading Whoogle config");
|
alert("Error loading Whoogle config");
|
||||||
|
@ -102,7 +102,7 @@ const saveConfig = event => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let configForm = document.getElementById("config-form");
|
let configForm = document.getElementById("config-form");
|
||||||
configForm.action = '/config?name=' + config + '.json';
|
configForm.action = '/config?name=' + config;
|
||||||
configForm.submit();
|
configForm.submit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user