From 217f86e5af41c9c49c74cf4823ea0c222d8b02cf Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 25 Jul 2022 22:05:04 +0000 Subject: [PATCH] Add uploads page --- public/uploads.html | 48 +++++++++++++++++++++++++++++++++++++++++++++ public/uploads.js | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 public/uploads.html create mode 100644 public/uploads.js 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 + + + + + + +
+ +
+ +
+
+ +
+
+ + + + + + 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();