diff --git a/public/uploads.html b/public/uploads.html new file mode 100644 index 0000000..784dbb8 --- /dev/null +++ b/public/uploads.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + Uploads + + + + + + +
+
+ +

Trip Schedule

+
+ +
+
+ +
+
+ +
+
+ + + + + + diff --git a/public/uploads.js b/public/uploads.js new file mode 100644 index 0000000..6d03465 --- /dev/null +++ b/public/uploads.js @@ -0,0 +1,43 @@ +const uploadTemplate = document.getElementById('upload-item'); +const uploadsContainer = document.getElementById('uploads'); + +async function main() { + const query = { + sort: 'filename', + limit: 50 + }; + + const stringifiedQuery = Qs.stringify({ + ...query + }, + { + addQueryPrefix: true + } + ); + + const uploads = await (await fetch(`/api/uploads${stringifiedQuery}`)).json(); + + console.log(uploads); + + if (uploads.errors) { + const $elem = document.createElement('span'); + $elem.classList.add('text-red-600'); + $elem.innerText = + uploads.errors[0].message + + '\nIf you are not logged in, please log in to view this page'; + + uploadsContainer.appendChild($elem); + return; + } + + for (const upload of uploads.docs) { + const $upload = uploadTemplate.content.cloneNode(true); + + $upload.querySelector('.upload-link').innerText = upload.filename; + $upload.querySelector('.upload-link').setAttribute('href', upload.url); + + uploadsContainer.append($upload); + } +} + +main();