From cd376ad61ac136857912d8a9ca0fa73127386c12 Mon Sep 17 00:00:00 2001 From: Vasil Vanchuk Date: Tue, 26 Aug 2025 23:57:30 +0300 Subject: [PATCH] Handle jsonUrl queryParam --- src/index.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/index.js b/src/index.js index 69b331a..df3ace1 100644 --- a/src/index.js +++ b/src/index.js @@ -181,3 +181,33 @@ async function handleFiles(files) { return rawData; } + +(function jsonFromUrl() { + // json via jsonUrl query param + + // Extract the 'jsonUrl' parameter from the URL + const urlParams = new URLSearchParams(window.location.search); + const jsonUrl = urlParams.get('jsonUrl'); + + console.log({ jsonUrl }); + + // Updated logic: run this on page load + if (jsonUrl) { + fetch(jsonUrl) + .then((res) => { + if (!res.ok) throw new Error('Failed to fetch'); + return res.text(); // or .json() if you want parsed object + }) + .then((text) => { + // Create a File object (only if your handleFiles requires it) + const blob = new Blob([text], { type: 'application/json' }); + const file = new File([blob], 'remote.json', { type: 'application/json' }); + + // Call handleFiles directly, bypassing the input altogether + handleFiles([file]).finally(destroyProgressBars).then(init); + }) + .catch((error) => { + console.error(`Could not load JSON from URL ${jsonUrl}`, error); + }); + } +})();