From 1ca178039c676a18bf15bb41bde0cdfa6e272d9b Mon Sep 17 00:00:00 2001 From: milahu Date: Sat, 18 Jul 2020 21:43:54 +0200 Subject: [PATCH 1/3] new URL format old format /?url=https%3A%2F%2Fhost%2Fpath%2Ffile.jpg&jpeg=0&bw=0&l=50 new format /https/host/path/file.jpg.c50.webp solve issue #22 new format must be supported by server (bandwidth-hero-proxy) --- src/background.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/background.js b/src/background.js index ec11518..ea47ebc 100644 --- a/src/background.js +++ b/src/background.js @@ -163,12 +163,14 @@ chrome.storage.local.get(storedState => { * @returns {string} */ function buildCompressUrl(url) { + const urlMatch = url.match(/^(\w+):\/\/(.*)$/); let redirectUrl = ''; redirectUrl += state.proxyUrl; - redirectUrl += `?url=${encodeURIComponent(url)}`; - redirectUrl += `&jpeg=${state.isWebpSupported ? 0 : 1}`; - redirectUrl += `&bw=${state.convertBw ? 1 : 0}`; - redirectUrl += `&l=${state.compressionLevel}`; + redirectUrl += urlMatch[1] + "/"; // protocol, mostly "https" + redirectUrl += urlMatch[2]; // rest of URL + redirectUrl += (state.convertBw ? ".b" : ".c"); // black-white or color + redirectUrl += state.compressionLevel; + redirectUrl += (state.isWebpSupported ? ".webp" : ".jpg"); return redirectUrl; } From c046fc1150b2f93966d87fdd6a5b30f2a12648d7 Mon Sep 17 00:00:00 2001 From: milahu Date: Mon, 20 Jul 2020 08:27:55 +0200 Subject: [PATCH 2/3] insert suffix between path and query string --- src/background.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index ea47ebc..cc04ceb 100644 --- a/src/background.js +++ b/src/background.js @@ -163,14 +163,17 @@ chrome.storage.local.get(storedState => { * @returns {string} */ function buildCompressUrl(url) { - const urlMatch = url.match(/^(\w+):\/\/(.*)$/); + const urlMatch = url.match(/^(\w+):\/\/(.*?)(\?.*)?$/); let redirectUrl = ''; redirectUrl += state.proxyUrl; redirectUrl += urlMatch[1] + "/"; // protocol, mostly "https" - redirectUrl += urlMatch[2]; // rest of URL + redirectUrl += urlMatch[2]; // host + path redirectUrl += (state.convertBw ? ".b" : ".c"); // black-white or color redirectUrl += state.compressionLevel; redirectUrl += (state.isWebpSupported ? ".webp" : ".jpg"); + if (urlMatch[3]) { + redirectUrl += urlMatch[3]; // query string + } return redirectUrl; } From 0e4b079680719e55969cb3931b676e673ee72d65 Mon Sep 17 00:00:00 2001 From: milahu Date: Tue, 21 Jul 2020 12:27:56 +0200 Subject: [PATCH 3/3] add internal query string before protocol --- src/background.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/background.js b/src/background.js index cc04ceb..e7beacf 100644 --- a/src/background.js +++ b/src/background.js @@ -163,16 +163,21 @@ chrome.storage.local.get(storedState => { * @returns {string} */ function buildCompressUrl(url) { - const urlMatch = url.match(/^(\w+):\/\/(.*?)(\?.*)?$/); + const urlMatch = url.match(/^(\w+):\/\/(.*?)(\/+)?(\?.*)?$/); let redirectUrl = ''; redirectUrl += state.proxyUrl; + if (urlMatch[3]) { + // trailing slashes in path are stripped + // add internal query string before protocol + redirectUrl += `appendPath=${encodeURIComponent(urlMatch[3])}/`; + } redirectUrl += urlMatch[1] + "/"; // protocol, mostly "https" redirectUrl += urlMatch[2]; // host + path redirectUrl += (state.convertBw ? ".b" : ".c"); // black-white or color redirectUrl += state.compressionLevel; redirectUrl += (state.isWebpSupported ? ".webp" : ".jpg"); - if (urlMatch[3]) { - redirectUrl += urlMatch[3]; // query string + if (urlMatch[4]) { + redirectUrl += urlMatch[4]; // query string } return redirectUrl; }