From 83463bda7435a30c0c7231f06491b2c988eb40ed Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Mon, 16 Dec 2024 15:28:32 -0500 Subject: [PATCH] Switch from GET to POST. --- module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php | 3 +-- themes/bootstrap3/js/doi.js | 9 +++++---- themes/bootstrap5/js/doi.js | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php b/module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php index 1bdb76bce29..c325f6a1bde 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php +++ b/module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php @@ -124,8 +124,7 @@ public function __construct( public function handleRequest(Params $params) { $response = []; - $rawIds = (array)$params->fromQuery('id', []); - $ids = array_map(fn ($id) => json_decode($id, true), $rawIds); + $ids = json_decode($params->getController()->getRequest()->getContent(), true); foreach ($this->resolvers as $resolver) { if ($this->pluginManager->has($resolver)) { $next = $this->pluginManager->get($resolver)->getLinks($ids); diff --git a/themes/bootstrap3/js/doi.js b/themes/bootstrap3/js/doi.js index 067ecf538a7..49e9996bcd7 100644 --- a/themes/bootstrap3/js/doi.js +++ b/themes/bootstrap3/js/doi.js @@ -3,9 +3,10 @@ VuFind.register('doi', function Doi() { function embedDoiLinks(el) { var queryParams = new URLSearchParams(); var elements = el.classList.contains('doiLink') ? [el] : el.querySelectorAll('.doiLink'); + var postBody = {}; elements.forEach(function extractIdentifierData(doiLinkEl) { var currentInstance = doiLinkEl.dataset.instance; - if (!queryParams.has(`id[${currentInstance}]`)) { + if (typeof postBody[currentInstance] === "undefined") { let currentIdentifiers = {}; ["doi", "issn", "isbn"].forEach(identifier => { if (typeof doiLinkEl.dataset[identifier] !== "undefined") { @@ -13,16 +14,16 @@ VuFind.register('doi', function Doi() { } }); if (Object.keys(currentIdentifiers).length > 0) { - queryParams.set(`id[${currentInstance}]`, JSON.stringify(currentIdentifiers)); + postBody[currentInstance] = currentIdentifiers; } } }); - if (queryParams.toString().length === 0) { + if (Object.keys(postBody).length === 0) { return; } queryParams.set("method", "doiLookup"); var url = VuFind.path + '/AJAX/JSON?' + queryParams.toString(); - fetch(url, { method: "GET" }) + fetch(url, { method: "POST", body: JSON.stringify(postBody) }) .then(function embedDoiLinksDone(rawResponse) { elements.forEach(function populateDoiLinks(doiEl) { var currentInstance = doiEl.dataset.instance; diff --git a/themes/bootstrap5/js/doi.js b/themes/bootstrap5/js/doi.js index 067ecf538a7..49e9996bcd7 100644 --- a/themes/bootstrap5/js/doi.js +++ b/themes/bootstrap5/js/doi.js @@ -3,9 +3,10 @@ VuFind.register('doi', function Doi() { function embedDoiLinks(el) { var queryParams = new URLSearchParams(); var elements = el.classList.contains('doiLink') ? [el] : el.querySelectorAll('.doiLink'); + var postBody = {}; elements.forEach(function extractIdentifierData(doiLinkEl) { var currentInstance = doiLinkEl.dataset.instance; - if (!queryParams.has(`id[${currentInstance}]`)) { + if (typeof postBody[currentInstance] === "undefined") { let currentIdentifiers = {}; ["doi", "issn", "isbn"].forEach(identifier => { if (typeof doiLinkEl.dataset[identifier] !== "undefined") { @@ -13,16 +14,16 @@ VuFind.register('doi', function Doi() { } }); if (Object.keys(currentIdentifiers).length > 0) { - queryParams.set(`id[${currentInstance}]`, JSON.stringify(currentIdentifiers)); + postBody[currentInstance] = currentIdentifiers; } } }); - if (queryParams.toString().length === 0) { + if (Object.keys(postBody).length === 0) { return; } queryParams.set("method", "doiLookup"); var url = VuFind.path + '/AJAX/JSON?' + queryParams.toString(); - fetch(url, { method: "GET" }) + fetch(url, { method: "POST", body: JSON.stringify(postBody) }) .then(function embedDoiLinksDone(rawResponse) { elements.forEach(function populateDoiLinks(doiEl) { var currentInstance = doiEl.dataset.instance;