Skip to content

Commit 0cb95c8

Browse files
committed
fix(pat contentbrowser): Use POST request for quering selected items in order to not get too long URIs when there are many items present.
1 parent 2b64636 commit 0cb95c8

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/pat/contentbrowser/src/utils.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,30 @@ export async function request({
104104
};
105105
const url_query = JSON.stringify(vocabQuery);
106106
const url_parameters = JSON.stringify(attributes);
107-
const url_batch = JSON.stringify({
107+
const url_batch = pageSize ? JSON.stringify({
108108
page: page,
109109
size: pageSize,
110-
});
110+
}) : "";
111+
112+
let url = `${vocabularyUrl}${vocabularyUrl.indexOf("?") !== -1 ? "&" : "?"}query=${url_query}&attributes=${url_parameters}` + (url_batch ? `&batch=${url_batch}` : "");
113+
let post_data = "";
111114

112-
const url = encodeURI(`${vocabularyUrl}${vocabularyUrl.indexOf("?") !== -1 ? "&" : "?"}query=${url_query}&attributes=${url_parameters}&batch=${url_batch}`);
113115
log.debug(url);
114116

115117
const headers = new Headers();
116118
headers.set("Accept", "application/json");
117119

120+
if (method == "POST" && vocabularyUrl.indexOf("?") !== -1) {
121+
const url_parts = vocabularyUrl.split("?");
122+
url = url_parts[0];
123+
post_data = url_parts[1];
124+
headers.set("Content-Type", "application/x-www-form-urlencoded");
125+
}
126+
118127
const response = await fetch(url, {
119128
method: method,
120129
headers: headers,
130+
body: post_data,
121131
});
122132

123133
if (!response.ok) {
@@ -153,9 +163,13 @@ export async function get_items_from_uids(uids, config) {
153163
return [];
154164
}
155165
const selectedItemsFromUids = await request({
166+
// use POST request (when many selected items are present the URL might get too long)
167+
method: "POST",
156168
vocabularyUrl: config.vocabularyUrl,
157169
attributes: config.attributes,
158170
uids: uids,
171+
// do not batch here, otherwise we do not get all items
172+
pageSize: null,
159173
});
160174
let results = (await selectedItemsFromUids?.results) || [];
161175
// resort the results based on the order of uids

0 commit comments

Comments
 (0)