mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Merge pull request #1943 from ser/payment-requests-subdirs
Spread payment requests to subdirs
This commit is contained in:
commit
c7ff3ba705
3 changed files with 16 additions and 9 deletions
|
@ -1046,13 +1046,13 @@ class Abstract_Wallet(PrintError):
|
||||||
rdir = config.get('requests_dir')
|
rdir = config.get('requests_dir')
|
||||||
if rdir:
|
if rdir:
|
||||||
key = out.get('id', addr)
|
key = out.get('id', addr)
|
||||||
path = os.path.join(rdir, key)
|
path = os.path.join(rdir, 'req', key[0], key[1], key)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
baseurl = 'file://' + rdir
|
baseurl = 'file://' + rdir
|
||||||
rewrite = config.get('url_rewrite')
|
rewrite = config.get('url_rewrite')
|
||||||
if rewrite:
|
if rewrite:
|
||||||
baseurl = baseurl.replace(*rewrite)
|
baseurl = baseurl.replace(*rewrite)
|
||||||
out['request_url'] = os.path.join(baseurl, key)
|
out['request_url'] = os.path.join(baseurl, 'req', key[0], key[1], key, key)
|
||||||
out['URI'] += '&r=' + out['request_url']
|
out['URI'] += '&r=' + out['request_url']
|
||||||
out['index_url'] = os.path.join(baseurl, 'index.html') + '?id=' + key
|
out['index_url'] = os.path.join(baseurl, 'index.html') + '?id=' + key
|
||||||
websocket_server_announce = config.get('websocket_server_announce')
|
websocket_server_announce = config.get('websocket_server_announce')
|
||||||
|
@ -1122,12 +1122,18 @@ class Abstract_Wallet(PrintError):
|
||||||
if rdir and amount is not None:
|
if rdir and amount is not None:
|
||||||
key = req.get('id', addr)
|
key = req.get('id', addr)
|
||||||
pr = paymentrequest.make_request(config, req)
|
pr = paymentrequest.make_request(config, req)
|
||||||
path = os.path.join(rdir, key)
|
path = os.path.join(rdir, 'req', key[0], key[1], key)
|
||||||
with open(path, 'w') as f:
|
if not os.path.exists(path):
|
||||||
|
try:
|
||||||
|
os.makedirs(path)
|
||||||
|
except OSError as exc:
|
||||||
|
if exc.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
with open(os.path.join(path, key), 'w') as f:
|
||||||
f.write(pr.SerializeToString())
|
f.write(pr.SerializeToString())
|
||||||
# reload
|
# reload
|
||||||
req = self.get_payment_request(addr, config)
|
req = self.get_payment_request(addr, config)
|
||||||
with open(os.path.join(rdir, key + '.json'), 'w') as f:
|
with open(os.path.join(path, key + '.json'), 'w') as f:
|
||||||
f.write(json.dumps(req))
|
f.write(json.dumps(req))
|
||||||
return req
|
return req
|
||||||
|
|
||||||
|
@ -1139,7 +1145,7 @@ class Abstract_Wallet(PrintError):
|
||||||
if rdir:
|
if rdir:
|
||||||
key = r.get('id', addr)
|
key = r.get('id', addr)
|
||||||
for s in ['.json', '']:
|
for s in ['.json', '']:
|
||||||
n = os.path.join(rdir, key + s)
|
n = os.path.join(rdir, 'req', key[0], key[1], key, key + s)
|
||||||
if os.path.exists(n):
|
if os.path.exists(n):
|
||||||
os.unlink(n)
|
os.unlink(n)
|
||||||
self.storage.put('payment_requests', self.receive_requests)
|
self.storage.put('payment_requests', self.receive_requests)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class WsClientThread(util.DaemonThread):
|
||||||
def make_request(self, request_id):
|
def make_request(self, request_id):
|
||||||
# read json file
|
# read json file
|
||||||
rdir = self.config.get('requests_dir')
|
rdir = self.config.get('requests_dir')
|
||||||
n = os.path.join(rdir, request_id + '.json')
|
n = os.path.join(rdir, 'req', request_id[0], request_id[1], request_id, request_id + '.json')
|
||||||
with open(n) as f:
|
with open(n) as f:
|
||||||
s = f.read()
|
s = f.read()
|
||||||
d = json.loads(s)
|
d = json.loads(s)
|
||||||
|
|
|
@ -25,7 +25,8 @@ function getUrlParameter(sParam)
|
||||||
var id = getUrlParameter('id');
|
var id = getUrlParameter('id');
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
var jqxhr = $.getJSON(id + ".json", function() {
|
var uri_path = location.pathname;
|
||||||
|
var jqxhr = $.getJSON(uri_path.replace("index.html", "req/"+ id[0] + "/"+ id[1] + "/"+ id + "/"+ id + ".json"), function() {
|
||||||
console.log("getJSON:success");
|
console.log("getJSON:success");
|
||||||
})
|
})
|
||||||
.done( function(data) {
|
.done( function(data) {
|
||||||
|
@ -60,7 +61,7 @@ if (id) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var wss_address = "wss://" + websocket_server + ":" + websocket_port +"/");
|
var wss_address = "wss://" + websocket_server + ":" + websocket_port +"/";
|
||||||
console.log("Opening WSS: " + wss_address)
|
console.log("Opening WSS: " + wss_address)
|
||||||
var ws = new WebSocket(wss_address);
|
var ws = new WebSocket(wss_address);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue