From 3353789146fd9d9a05dc3dc0cd606a2004501a35 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Wed, 22 Nov 2023 00:23:01 +0400 Subject: [PATCH] fix: dropbox sharing maps --- index.html | 4 ++-- modules/io/cloud.js | 4 ++-- modules/io/load.js | 23 ++++++++++------------- versioning.js | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 1cf490c1..ff9c45e2 100644 --- a/index.html +++ b/index.html @@ -7989,8 +7989,8 @@ - - + + diff --git a/modules/io/cloud.js b/modules/io/cloud.js index 01338c0b..4e174194 100644 --- a/modules/io/cloud.js +++ b/modules/io/cloud.js @@ -118,9 +118,9 @@ window.Cloud = (function () { }, async getLink(path) { - // return existitng shared link + // return existing shared link const sharedLinks = await this.call("sharingListSharedLinks", {path}); - if (sharedLinks.result.links.length) return resp.result.links[0].url; + if (sharedLinks.result.links.length) return sharedLinks.result.links[0].url; // create new shared link const settings = { diff --git a/modules/io/load.js b/modules/io/load.js index f2154872..d3c97efe 100644 --- a/modules/io/load.js +++ b/modules/io/load.js @@ -21,22 +21,19 @@ async function createSharableDropboxLink() { const mapFile = document.querySelector("#loadFromDropbox select").value; const sharableLink = document.getElementById("sharableLink"); const sharableLinkContainer = document.getElementById("sharableLinkContainer"); - let url; + try { - url = await Cloud.providers.dropbox.getLink(mapFile); - } catch { + const previewLink = await Cloud.providers.dropbox.getLink(mapFile); + const directLink = previewLink.replace("www.dropbox.com", "dl.dropboxusercontent.com"); // DL allows CORS + const finalLink = `${location.origin}${location.pathname}?maplink=${directLink}`; + + sharableLink.innerText = finalLink.slice(0, 45) + "..."; + sharableLink.setAttribute("href", finalLink); + sharableLinkContainer.style.display = "block"; + } catch (error) { + ERROR && console.error(error); return tip("Dropbox API error. Can not create link.", true, "error", 2000); } - - const fmg = window.location.href.split("?")[0]; - const reallink = `${fmg}?maplink=${url}`; - // voodoo magic required by the yellow god of CORS - const link = reallink.replace("www.dropbox.com/s/", "dl.dropboxusercontent.com/1/view/"); - const shortLink = link.slice(0, 50) + "..."; - - sharableLinkContainer.style.display = "block"; - sharableLink.innerText = shortLink; - sharableLink.setAttribute("href", link); } function loadMapPrompt(blob) { diff --git a/versioning.js b/versioning.js index cdcb00b6..e6d0c034 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.94.03"; // generator version, update each time +const version = "1.94.04"; // generator version, update each time { document.title += " v" + version;