fix web request server. fixes #1455
This commit is contained in:
parent
dd679ccb27
commit
f3bd1662f7
26
electrum
26
electrum
|
@ -407,28 +407,6 @@ def get_daemon(config, start_daemon):
|
|||
|
||||
|
||||
|
||||
def check_www_dir(rdir):
|
||||
# rewrite index.html every time
|
||||
import urllib, urlparse, shutil, os
|
||||
if not os.path.exists(rdir):
|
||||
os.mkdir(rdir)
|
||||
index = os.path.join(rdir, 'index.html')
|
||||
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
|
||||
shutil.copy(src, index)
|
||||
files = [
|
||||
"https://code.jquery.com/jquery-1.9.1.min.js",
|
||||
"https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/qrcode.js",
|
||||
"https://code.jquery.com/ui/1.10.3/jquery-ui.js",
|
||||
"https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"
|
||||
]
|
||||
for URL in files:
|
||||
path = urlparse.urlsplit(URL).path
|
||||
filename = os.path.basename(path)
|
||||
path = os.path.join(rdir, filename)
|
||||
if not os.path.exists(path):
|
||||
print_error("downloading ", URL)
|
||||
urllib.urlretrieve(URL, path)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -546,10 +524,10 @@ if __name__ == '__main__':
|
|||
network.start()
|
||||
server = NetworkServer(config, network)
|
||||
if config.get('websocket_server'):
|
||||
import websockets
|
||||
from electrum import websockets
|
||||
websockets.WebSocketServer(config, server).start()
|
||||
if config.get('requests_dir'):
|
||||
check_www_dir(config.get('requests_dir'))
|
||||
util.check_www_dir(config.get('requests_dir'))
|
||||
server.start()
|
||||
server.join()
|
||||
else:
|
||||
|
|
|
@ -532,7 +532,7 @@ class Commands:
|
|||
PR_PAID: 'Paid',
|
||||
PR_EXPIRED: 'Expired',
|
||||
}
|
||||
out['amount'] = format_satoshis(out.get('amount')) + ' BTC'
|
||||
out['amount (BTC)'] = format_satoshis(out.pop('amount'))
|
||||
out['status'] = pr_str[out.get('status', PR_UNKNOWN)]
|
||||
return out
|
||||
|
||||
|
|
26
lib/util.py
26
lib/util.py
|
@ -524,3 +524,29 @@ class StoreDict(dict):
|
|||
if key in self.keys():
|
||||
dict.pop(self, key)
|
||||
self.save()
|
||||
|
||||
|
||||
|
||||
|
||||
def check_www_dir(rdir):
|
||||
# rewrite index.html every time
|
||||
import urllib, urlparse, shutil, os
|
||||
if not os.path.exists(rdir):
|
||||
os.mkdir(rdir)
|
||||
index = os.path.join(rdir, 'index.html')
|
||||
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
|
||||
shutil.copy(src, index)
|
||||
files = [
|
||||
"https://code.jquery.com/jquery-1.9.1.min.js",
|
||||
"https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/qrcode.js",
|
||||
"https://code.jquery.com/ui/1.10.3/jquery-ui.js",
|
||||
"https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"
|
||||
]
|
||||
for URL in files:
|
||||
path = urlparse.urlsplit(URL).path
|
||||
filename = os.path.basename(path)
|
||||
path = os.path.join(rdir, filename)
|
||||
if not os.path.exists(path):
|
||||
print_error("downloading ", URL)
|
||||
urllib.urlretrieve(URL, path)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ except ImportError:
|
|||
print "install SimpleWebSocketServer"
|
||||
sys.exit()
|
||||
|
||||
import util, daemon
|
||||
import util
|
||||
|
||||
request_queue = Queue.Queue()
|
||||
|
||||
|
@ -44,7 +44,7 @@ class ElectrumWebSocket(WebSocket):
|
|||
|
||||
|
||||
|
||||
class WsClientThread(daemon.ClientThread):
|
||||
class WsClientThread(util.DaemonThread):
|
||||
|
||||
def __init__(self, config, server):
|
||||
util.DaemonThread.__init__(self)
|
||||
|
|
Loading…
Reference in New Issue