Skip to content

Commit 48068c0

Browse files
committed
request caching
1 parent 69cd1fd commit 48068c0

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

assets_js_bitrequest_core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,8 +3774,9 @@ function share_receipt() {
37743774
loader(true);
37753775
loadertext(translate("generatereceipt"));
37763776
const accountname = $("#accountsettings").data("selected"),
3777-
sharedtitle = "bitrequest_receipt_" + requestid + ".pdf";
3778-
shorten_url(sharedtitle, href, fetch_aws("img_receipt_icon.png"), true);
3777+
sharedtitle = "bitrequest_receipt_" + requestid + ".pdf",
3778+
url_hash = hashcode(requestid + sharedtitle);
3779+
shorten_url(sharedtitle, href, fetch_aws("img_receipt_icon.png"), true, url_hash);
37793780
closeloader();
37803781
}
37813782
})

assets_js_bitrequest_payments.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,8 @@ function share(thisbutton) {
23712371
newdatastring = thisdata ? "&d=" + dataparam : "", // construct data param if exists
23722372
isipfs = glob_thishostname.includes("ipfs") || glob_thishostname.includes("bitrequest.crypto"),
23732373
shared_host = isipfs ? glob_c_host : "https://bitrequest.github.io", // check for IFPS
2374-
sharedurl = shared_host + "/?p=requests&payment=" + payment + "&uoa=" + thiscurrency + "&amount=" + thisamount + "&address=" + thisaddress + newdatastring,
2374+
url_id = shared_host + "/?p=requests&payment=" + payment + "&uoa=" + thiscurrency + "&amount=" + thisamount + "&address=" + thisaddress,
2375+
sharedurl = url_id + newdatastring,
23752376
thisrequestname_uppercase = capitalize(thisrequestname), // capitalize requestname
23762377
paymentupper = capitalize(payment),
23772378
payment_name = lightning ? "Lightning" : paymentupper,
@@ -2392,7 +2393,8 @@ function share(thisbutton) {
23922393
setlocales();
23932394
return
23942395
}
2395-
shorten_url(sharedtitle, sharedurl, share_icon);
2396+
const url_hash = hashcode(url_id + sharedtitle);
2397+
shorten_url(sharedtitle, sharedurl, share_icon, null, url_hash);
23962398
setlocales();
23972399
return
23982400

@@ -2413,43 +2415,43 @@ function share(thisbutton) {
24132415
}
24142416

24152417
// Handles URL shortening and sharing process
2416-
function shorten_url(sharedtitle, sharedurl, sitethumb, unguessable) {
2418+
function shorten_url(sharedtitle, sharedurl, sitethumb, unguessable, url_hash) {
24172419
loadertext(translate("generatelink"));
24182420
const us_settings = $("#url_shorten_settings"),
24192421
us_active = us_settings.data("us_active") === "active";
24202422
if (us_active) {
24212423
const us_service = us_settings.data("selected"),
24222424
is_custom = us_service.indexOf("https://") >= 0;
2423-
cache_prefix = is_custom ? "custom" : us_service,
2424-
getcache = br_get_session(cache_prefix + "_shorturl_" + hashcode(sharedurl));
2425-
if (getcache) {
2426-
sharerequest(getcache, sharedtitle);
2427-
return;
2425+
if (url_hash) {
2426+
const cache_prefix = is_custom ? "custom" : us_service,
2427+
getcache = br_get_session(cache_prefix + "_shorturl_" + url_hash);
2428+
if (getcache) {
2429+
sharerequest(getcache, sharedtitle);
2430+
return;
2431+
}
24282432
}
24292433
if (us_service === "firebase") {
2430-
firebase_shorten(sharedurl, sharedtitle, sitethumb, unguessable);
2434+
firebase_shorten(sharedurl, sharedtitle, sitethumb, unguessable, url_hash);
24312435
return;
24322436
}
24332437
if (us_service === "bitly") {
2434-
bitly_shorten(sharedurl, sharedtitle);
2438+
bitly_shorten(sharedurl, sharedtitle, url_hash);
24352439
return;
24362440
}
24372441
if (is_custom) {
2438-
custom_shorten(us_service, sharedurl, sharedtitle, sitethumb);
2442+
custom_shorten(us_service, sharedurl, sharedtitle, sitethumb, url_hash);
24392443
return;
24402444
}
24412445
}
24422446
sharerequest(sharedurl, sharedtitle);
24432447
}
24442448

24452449
// Handles Firebase URL shortening
2446-
function firebase_shorten(sharedurl, sharedtitle, sitethumb, unguessable) {
2450+
function firebase_shorten(sharedurl, sharedtitle, sitethumb, unguessable, url_hash) {
24472451
const security = unguessable ? "UNGUESSABLE" : "SHORT";
24482452
api_proxy({
24492453
"api": "firebase",
24502454
"search": "shortLinks",
2451-
"cachetime": 84600,
2452-
"cachefolder": "1d",
24532455
"params": {
24542456
"method": "POST",
24552457
"cache": false,
@@ -2482,24 +2484,26 @@ function firebase_shorten(sharedurl, sharedtitle, sitethumb, unguessable) {
24822484
const data = br_result(e).result;
24832485
if (data) {
24842486
if (data.error) {
2485-
custom_shorten(false, sharedurl, sharedtitle, sitethumb);
2487+
custom_shorten(false, sharedurl, sharedtitle, sitethumb, url_hash);
24862488
return
24872489
}
24882490
const shorturl = data.shortLink;
24892491
if (shorturl) {
24902492
sharerequest(shorturl, sharedtitle);
2491-
br_set_session("firebase_shorturl_" + hashcode(sharedurl), shorturl);
2493+
if (url_hash) {
2494+
br_set_session("firebase_shorturl_" + url_hash, shorturl);
2495+
}
24922496
return
24932497
}
24942498
}
2495-
custom_shorten(false, sharedurl, sharedtitle, sitethumb);
2499+
custom_shorten(false, sharedurl, sharedtitle, sitethumb, url_hash);
24962500
}).fail(function() {
2497-
custom_shorten(false, sharedurl, sharedtitle, sitethumb);
2501+
custom_shorten(false, sharedurl, sharedtitle, sitethumb, url_hash);
24982502
});
24992503
}
25002504

25012505
// Handles Bitly URL shortening
2502-
function bitly_shorten(sharedurl, sharedtitle) {
2506+
function bitly_shorten(sharedurl, sharedtitle, url_hash) {
25032507
api_proxy({
25042508
"api": "bitly",
25052509
"search": "bitlinks",
@@ -2519,7 +2523,9 @@ function bitly_shorten(sharedurl, sharedtitle) {
25192523
const linkid = data.id.split("/").pop(),
25202524
shurl = glob_approot + "?i=4bR" + linkid;
25212525
sharerequest(shurl, sharedtitle);
2522-
br_set_session("bitly_shorturl_" + hashcode(sharedurl), shurl);
2526+
if (url_hash) {
2527+
br_set_session("bitly_shorturl_" + url_hash, shurl);
2528+
}
25232529
return
25242530
}
25252531
sharerequest(sharedurl, sharedtitle);
@@ -2529,7 +2535,7 @@ function bitly_shorten(sharedurl, sharedtitle) {
25292535
}
25302536

25312537
// Handles Custom URL shortening
2532-
function custom_shorten(service, sharedurl, sharedtitle, sitethumb) {
2538+
function custom_shorten(service, sharedurl, sharedtitle, sitethumb, url_hash) {
25332539
const serv = service || d_proxy(),
25342540
rqdat = btoa(JSON.stringify({
25352541
"sharedurl": sharedurl,
@@ -2552,7 +2558,7 @@ function custom_shorten(service, sharedurl, sharedtitle, sitethumb) {
25522558
if (data) {
25532559
if (data.error) {
25542560
notify(serv + ": " + data.error, 500000, "yes");
2555-
bitly_shorten(sharedurl, sharedtitle);
2561+
bitly_shorten(sharedurl, sharedtitle, url_hash);
25562562
return
25572563
}
25582564
const rqid = data.shorturl;
@@ -2561,13 +2567,15 @@ function custom_shorten(service, sharedurl, sharedtitle, sitethumb) {
25612567
isdefault = index > -1;
25622568
shurl = isdefault ? glob_approot + "?i=" + index.toString() + rqid : serv + "proxy/v1/inv/4bR" + rqid;
25632569
sharerequest(shurl, sharedtitle);
2564-
br_set_session("custom_shorturl_" + hashcode(sharedurl), shurl);
2570+
if (url_hash) {
2571+
br_set_session("custom_shorturl_" + url_hash, shurl);
2572+
}
25652573
return
25662574
}
25672575
}
2568-
bitly_shorten(sharedurl, sharedtitle);
2576+
bitly_shorten(sharedurl, sharedtitle, url_hash);
25692577
}).fail(function() {
2570-
bitly_shorten(sharedurl, sharedtitle);
2578+
bitly_shorten(sharedurl, sharedtitle, url_hash);
25712579
});
25722580
}
25732581

0 commit comments

Comments
 (0)