Skip to content

Commit

Permalink
Switch from GET to POST.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 16, 2024
1 parent 7d78911 commit 83463bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions themes/bootstrap3/js/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ 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") {
currentIdentifiers[identifier] = doiLinkEl.dataset[identifier];
}
});
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;
Expand Down
9 changes: 5 additions & 4 deletions themes/bootstrap5/js/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ 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") {
currentIdentifiers[identifier] = doiLinkEl.dataset[identifier];
}
});
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;
Expand Down

0 comments on commit 83463bd

Please sign in to comment.