Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions frontend/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,28 +286,52 @@ export async function SBHLogin(url, username, password) {
}
}

function normalizeCollectionResponse(data) {
if (Array.isArray(data)) {
return data;
}

if (data?.results && Array.isArray(data.results)) {
return data.results;
}

if (data?.collections && Array.isArray(data.collections)) {
return data.collections;
}

if (data?.rootCollections && Array.isArray(data.rootCollections)) {
return data.rootCollections;
}

return [];
}

export async function searchCollections(url, auth) {
try {
if (typeof url !== "string" || url.trim() === "") return null;
if (typeof url !== "string" || url.trim() === "") return [];

const response = await axios.get(`${url}/rootCollections`, {
headers: {
"Content-Type": "text/plain",
"X-authorization": auth
}
});

// This filters out all the public root collections so only private ones are returned
if (Array.isArray(response.data)) {
return response.data.filter(item => typeof item.uri === 'string' && !/\/public\//.test(item.uri));
} else {
throw new Error("Response from SynbioHub is not an array");
}
const collections = normalizeCollectionResponse(response.data);

return collections.filter(
item => typeof item.uri === 'string' && !/\/public\//.test(item.uri)
);
} catch (error) {
if (error.response && error.response.status == 401 && error.response.data == "Login required"){
showErrorNotification('Your SynbioHub Credentials Have Expired', "Try logging out and logging back in again")
if (error.response && error.response.status == 401 && error.response.data == "Login required") {
showErrorNotification(
'Your SynbioHub Credentials Have Expired',
"Try logging out and logging back in again"
);
} else {
showErrorNotification('Error Gathering Collections', error.message);
}

throw error;
}
}
Expand Down Expand Up @@ -484,4 +508,4 @@ export function clearInvalidCredentials(instanceUrl) {
} catch (error) {
console.error('Error clearing invalid credentials:', error);
}
}
}
Loading