Add uploads page
This commit is contained in:
43
public/uploads.js
Normal file
43
public/uploads.js
Normal file
@@ -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();
|
||||
Reference in New Issue
Block a user