Initial commit
This commit is contained in:
commit
f583b9af02
152
_list.html
Normal file
152
_list.html
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" style="height:100%">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<title>happyDomain downloads</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>
|
||||||
|
Index of <span id="page_path"><script>document.write(window.location.pathname.replace(/_list.html$/, ''))</script></span>
|
||||||
|
</h1>
|
||||||
|
<hr>
|
||||||
|
<noscript>
|
||||||
|
Sorry, this page uses Javascript to display directory content.<br>
|
||||||
|
You can use the route <a href="/_list">/_list</a> to retrieve the list in XML format.
|
||||||
|
</noscript>
|
||||||
|
<pre id="bucket_list">Please wait…</pre>
|
||||||
|
<hr>
|
||||||
|
<script>
|
||||||
|
function getLastModified(subtree) {
|
||||||
|
let lastmodified = new Date(0);
|
||||||
|
|
||||||
|
for (const sub in subtree.dirs) {
|
||||||
|
const lm = getLastModified(subtree.dirs[sub]);
|
||||||
|
if (lm > lastmodified) {
|
||||||
|
lastmodified = lm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const sub in subtree.files) {
|
||||||
|
const lm = new Date(subtree.files[sub].lastmodified)
|
||||||
|
if (lm > lastmodified) {
|
||||||
|
lastmodified = lm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastmodified
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEntries() {
|
||||||
|
const tree = {
|
||||||
|
dirs: {},
|
||||||
|
files: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await fetch(window.origin + '/_list');
|
||||||
|
const data = new window.DOMParser().parseFromString(await res.text(), "text/xml");
|
||||||
|
for (const i of data.getElementsByTagName('Contents')) {
|
||||||
|
const path = i.getElementsByTagName('Key')[0].textContent.split('/');
|
||||||
|
const filename = path.pop();
|
||||||
|
|
||||||
|
let ptree = tree;
|
||||||
|
for (const d of path) {
|
||||||
|
if (!ptree.dirs[d]) {
|
||||||
|
ptree.dirs[d] = {
|
||||||
|
dirs: {},
|
||||||
|
files: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
ptree = ptree.dirs[d];
|
||||||
|
}
|
||||||
|
|
||||||
|
const owner = i.getElementsByTagName('Owner')[0];
|
||||||
|
|
||||||
|
ptree.files[filename] = {
|
||||||
|
lastmodified: i.getElementsByTagName('LastModified')[0].textContent,
|
||||||
|
etag: i.getElementsByTagName('ETag')[0].textContent,
|
||||||
|
size: i.getElementsByTagName('Size')[0].textContent,
|
||||||
|
owner: {
|
||||||
|
id: owner.getElementsByTagName('ID')[0].textContent,
|
||||||
|
displayname: owner.getElementsByTagName('DisplayName')[0].textContent,
|
||||||
|
},
|
||||||
|
storageclass: i.getElementsByTagName('StorageClass')[0].textContent,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayEntries(tree, underpath) {
|
||||||
|
document.getElementById('bucket_list').innerHTML = '';
|
||||||
|
document.getElementById('page_path').innerText = underpath.join('/');
|
||||||
|
|
||||||
|
underpath.shift();
|
||||||
|
underpath.pop();
|
||||||
|
let mtree = tree;
|
||||||
|
for (const p of underpath) {
|
||||||
|
if (mtree) {
|
||||||
|
mtree = mtree.dirs[p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const table = document.getElementById('bucket_list');
|
||||||
|
|
||||||
|
if (underpath.length > 0) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.innerText = '../';
|
||||||
|
link.href = '../';
|
||||||
|
link.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
history.pushState(null, document.title, '../')
|
||||||
|
underpath.pop();
|
||||||
|
displayEntries(tree, ('/' + underpath.join('/') + (underpath.length > 0?'/':'')).split('/'))
|
||||||
|
});
|
||||||
|
table.appendChild(link);
|
||||||
|
table.appendChild(document.createTextNode('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const dirname in mtree.dirs) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.innerText = dirname + '/';
|
||||||
|
link.href = dirname + '/';
|
||||||
|
link.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
history.pushState(null, document.title, './' + dirname + '/');
|
||||||
|
underpath.push(dirname);
|
||||||
|
displayEntries(tree, ('/' + underpath.join('/') + '/').split('/'))
|
||||||
|
});
|
||||||
|
table.appendChild(link);
|
||||||
|
table.appendChild(document.createTextNode(' '.repeat(50 - dirname.length)));
|
||||||
|
|
||||||
|
const lastmod = getLastModified(mtree.dirs[dirname]);
|
||||||
|
|
||||||
|
table.appendChild(document.createTextNode(new Intl.DateTimeFormat('default', {year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: false}).format(lastmod) + ' '.repeat(19)));
|
||||||
|
|
||||||
|
table.appendChild(document.createTextNode('-\n'));
|
||||||
|
}
|
||||||
|
for (const filename in mtree.files) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.innerText = filename;
|
||||||
|
link.href = filename;
|
||||||
|
table.appendChild(link);
|
||||||
|
table.appendChild(document.createTextNode(' '.repeat(51 - filename.length)));
|
||||||
|
|
||||||
|
const lastmod = new Date(mtree.files[filename].lastmodified)
|
||||||
|
|
||||||
|
table.appendChild(document.createTextNode(new Intl.DateTimeFormat('default', {year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: false}).format(lastmod) + ' '.repeat(20 - mtree.files[filename].size.length)));
|
||||||
|
table.appendChild(document.createTextNode(mtree.files[filename].size));
|
||||||
|
table.appendChild(document.createTextNode('\n'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getEntries().then(function (ents) {
|
||||||
|
displayEntries(ents, window.location.pathname.split('/'));
|
||||||
|
window.onpopstate = function(event) {
|
||||||
|
displayEntries(ents, window.location.pathname.split('/'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user