From 17937b2db63cb32d82d35c950f65e10a7078bedf Mon Sep 17 00:00:00 2001 From: Jacob Strieb Date: Sun, 19 Jul 2020 15:11:40 -0400 Subject: [PATCH] Use versioned API with (hopefully) shorter URLs --- api.js | 10 ++++++++-- editor/editor.js | 6 +++--- index.html | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api.js b/api.js index 1262105..719deca 100644 --- a/api.js +++ b/api.js @@ -12,8 +12,7 @@ * Global Variables ******************************************************************************/ -const LATEST_API_VERSION = "0.0.1"; -// const LATEST_API_VERSION = "0.2.0"; +const LATEST_API_VERSION = "0.2.0"; var apiVersions = {}; @@ -31,12 +30,19 @@ apiVersions["0.2.0"] = { getViewLink: function(pageData) { var urlData = { version: this.VERSION, + compressed: false, + body: pageData, }; const hashObject = b64.encode(JSON.stringify(urlData)); return `http://jstrieb.github.io/urlpages/#${hashObject}`; }, + /* Return the page data from the object */ + decode: function(urlData) { + return urlData.body; + }, + } diff --git a/editor/editor.js b/editor/editor.js index 4436aa8..44ea04c 100644 --- a/editor/editor.js +++ b/editor/editor.js @@ -50,7 +50,7 @@ function setViewUrl() { "html" : document.getElementById("html").value }; - var html = encodeURIComponent(getHTML(data)); + var html = getHTML(data); // Update the URL for the "Short Link" button document.getElementById("url").value = api.getViewLink(html); @@ -118,7 +118,7 @@ function update() { "html" : document.getElementById("html").value }; - var html = encodeURIComponent(getHTML(data)); + var html = getHTML(data); // Save encoded page data to the URL window.location.hash = "#" + b64.encode(JSON.stringify(data)); @@ -130,5 +130,5 @@ function update() { document.getElementById("downloadLink").href = `data:text/html,${html}` // Update the