Move to git.themmonk.com
This commit is contained in:
49
web/js/libraries.js
Normal file
49
web/js/libraries.js
Normal file
@@ -0,0 +1,49 @@
|
||||
//auth.js handles accessToken
|
||||
//const accessToken = localStorage.getItem("accessToken");
|
||||
|
||||
//only to be used by /web/libraries, not general purpose
|
||||
|
||||
async function getAllLibraries() {
|
||||
try {
|
||||
const response = await fetch('/libraries', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
alert("Error: access forbidden, please reauthenticate if error persists");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.status !== 200) {
|
||||
console.error('Unexpected HTTP status code', response.status);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const libraries = data.AvailableLibraries;
|
||||
|
||||
const container = document.getElementById("library-entry-container");
|
||||
const template = document.getElementById("library-template");
|
||||
|
||||
container.innerHTML = "";
|
||||
|
||||
libraries.forEach(lib => {
|
||||
const clone = template.content.cloneNode(true);
|
||||
const link = clone.querySelector(".library-viewer-href");
|
||||
|
||||
link.textContent = lib.Name;
|
||||
link.href = `/web/library_viewer?lib=${encodeURIComponent(lib.PathName)}&path=/`;
|
||||
|
||||
container.appendChild(clone);
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
alert("Network or server error");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
getAllLibraries();
|
||||
Reference in New Issue
Block a user