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 json
|
||||
import os
|
||||
import pickle
|
||||
import urllib.parse as urlparse
|
||||
from requests import exceptions
|
||||
import uuid
|
||||
|
@ -156,8 +157,8 @@ def config():
|
|||
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']
|
||||
config_pkl = os.path.join(app.config['CONFIG_PATH'], request.args.get('name'))
|
||||
session['config'] = pickle.load(open(config_pkl, 'rb')) if os.path.exists(config_pkl) else session['config']
|
||||
return json.dumps(session['config'])
|
||||
else:
|
||||
return json.dumps({})
|
||||
|
@ -167,9 +168,7 @@ def config():
|
|||
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()
|
||||
pickle.dump(config_data, open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'wb'))
|
||||
|
||||
session['config'] = config_data
|
||||
return redirect(config_data['url'])
|
||||
|
|
|
@ -80,7 +80,7 @@ const loadConfig = event => {
|
|||
}
|
||||
|
||||
let xhrPUT = new XMLHttpRequest();
|
||||
xhrPUT.open("PUT", "/config?name=" + config + '.json');
|
||||
xhrPUT.open("PUT", "/config?name=" + config);
|
||||
xhrPUT.onload = function() {
|
||||
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
||||
alert("Error loading Whoogle config");
|
||||
|
@ -102,7 +102,7 @@ const saveConfig = event => {
|
|||
}
|
||||
|
||||
let configForm = document.getElementById("config-form");
|
||||
configForm.action = '/config?name=' + config + '.json';
|
||||
configForm.action = '/config?name=' + config;
|
||||
configForm.submit();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user