|
|
@@ -1,7 +1,7 @@
|
|
|
|
|
|
(()=>{
|
|
|
- const NOW = Date.now();
|
|
|
let tmp = new Date();
|
|
|
+ const NOW = tmp.getTime();
|
|
|
tmp.setHours(0);
|
|
|
tmp.setMinutes(0);
|
|
|
tmp.setSeconds(0);
|
|
|
@@ -11,27 +11,86 @@
|
|
|
if (tmp.getDay() !== 1)
|
|
|
tmp.setDate(tmp.getDate()-tmp.getDay() +1);
|
|
|
const ONE_WEEK = tmp.getTime();
|
|
|
- console.log(tmp);
|
|
|
tmp.setTime(today);
|
|
|
tmp.setDate(1);
|
|
|
const ONE_MONTH = tmp.getTime();
|
|
|
- console.log(tmp);
|
|
|
+ const relSource = document.getElementById("relSource");
|
|
|
|
|
|
- for (let i of ["All"].concat(Object.keys(ACCESS.reduce((acc, i) => { acc[i.publicId] = true; return acc; }, {})).sort())) {
|
|
|
- let node = document.createElement("option");
|
|
|
- node.textContent = i;
|
|
|
- document.getElementById("relSource").appendChild(node);
|
|
|
+ /* INIT DROPDOWN */ (() => {
|
|
|
+ let frag = document.createDocumentFragment();
|
|
|
+ let origins = ACCESS.reduce((acc, i) => { acc[i.publicId] = true; return acc; }, {});
|
|
|
+ for (let i of ORIGINS) origins[i] = true;
|
|
|
+ for (let i of (["All"].concat(Object.keys(origins).sort())).map(i => {
|
|
|
+ let node = document.createElement("option");
|
|
|
+ node.textContent = i;
|
|
|
+ return node;
|
|
|
+ }))
|
|
|
+ frag.appendChild(i);
|
|
|
+ relSource.appendChild(frag);
|
|
|
+ })();
|
|
|
+
|
|
|
+ function formatDate(d) {
|
|
|
+ if (!d || isNaN(d.getTime()))
|
|
|
+ return "";
|
|
|
+ return d.toLocaleDateString() + " " + d.toLocaleTimeString();
|
|
|
+ }
|
|
|
+
|
|
|
+ function prependDomain(xmlElement) {
|
|
|
+ xmlElement.textContent = document.location.origin + xmlElement.textContent;
|
|
|
}
|
|
|
+
|
|
|
+ function generateQrCode(size, rel) {
|
|
|
+ if (rel)
|
|
|
+ rel = "&rel="+encodeURIComponent(rel);
|
|
|
+ return "/" +PUBLIC_ID +"/qrcode.png?origin="+encodeURIComponent(document.location.origin)+'&s='+size +(rel || "");
|
|
|
+ }
|
|
|
+
|
|
|
+ let HASH_CHANGING = false;
|
|
|
+
|
|
|
function selectSource(source) {
|
|
|
let _access = source === "All" ? ACCESS : ACCESS.filter(i => i.publicId === source);
|
|
|
- let lastAccess = _access.reduce((prev, i) => (prev && prev.accessTime > i.accessTime) ? prev : i, null)
|
|
|
- document.getElementById("size").textContent = FILE_SIZE +'o';
|
|
|
+ let lastAccess = _access.reduce((prev, i) => (prev && prev.accessTime > i.accessTime) ? prev : i, null);
|
|
|
document.getElementById('totalAccessCount').textContent = _access.length;
|
|
|
- document.getElementById('weekAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= NOW -ONE_WEEK ? 1 : 0), 0);
|
|
|
- document.getElementById('monthAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= NOW -ONE_MONTH ? 1 : 0), 0);
|
|
|
- document.getElementById('lastAccess').textContent = new Date(lastAccess?.accessTime);
|
|
|
+ document.getElementById('weekAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= ONE_WEEK ? 1 : 0), 0);
|
|
|
+ document.getElementById('monthAccess').textContent = _access.reduce((acc, i) => acc + (i.accessTime >= ONE_MONTH ? 1 : 0), 0);
|
|
|
+ document.getElementById('lastAccess').textContent = formatDate(new Date(lastAccess?.accessTime));
|
|
|
+ document.getElementById("publicLinkQr").innerHTML = "<img src='" +generateQrCode(150, !source || source === "All" ? null : source) +"'/>";
|
|
|
+ document.getElementById("publicLinkQrBig").href = generateQrCode(1024, !source || source === "All" ? null : source);
|
|
|
+ const linkEnd = PUBLIC_ID + (!source || source === "All" ? "" : ("?r=" +source));
|
|
|
+ document.getElementById("publicLink").textContent = document.location.origin + "/x/" + linkEnd;
|
|
|
+ document.getElementById("embedLink").textContent = document.location.origin + "/x/raw/" + linkEnd;
|
|
|
+ document.getElementById("publicLinkA").href = "/x/" +linkEnd;
|
|
|
+ document.getElementById("embedLinkA").href = "/x/raw/" +linkEnd;
|
|
|
+ HASH_CHANGING = true;
|
|
|
+ document.location.hash = encodeURIComponent(source);
|
|
|
+ HASH_CHANGING = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateSource() {
|
|
|
+ const selected = relSource.selectedOptions?.[0]?.textContent;
|
|
|
+ selectSource(selected || selected === '' ? selected : "All");
|
|
|
}
|
|
|
- selectSource(document.getElementById("relSource").selectedOptions?.[0]?.textContent || "All");
|
|
|
- document.getElementById("relSource").addEventListener("change", () => selectSource(document.getElementById("relSource").selectedOptions?.[0]?.textContent || "All"));
|
|
|
+ function hashChanged() {
|
|
|
+ if (HASH_CHANGING) return;
|
|
|
+ if (document.location.hash) {
|
|
|
+ const hash = (decodeURIComponent(document.location.hash.substring(1)));
|
|
|
+ selectSource(hash);
|
|
|
+ for (let i =0; i < relSource.children.length; ++i) {
|
|
|
+ if (relSource.children[i].textContent === hash) {
|
|
|
+ relSource.selectedIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ updateSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hashChanged();
|
|
|
+
|
|
|
+ addEventListener("hashchange", hashChanged);
|
|
|
+ relSource.addEventListener("change", () => updateSource());
|
|
|
+ document.getElementById("size").textContent = FILE_SIZE +'o';
|
|
|
+ document.getElementById("creationTime").textContent = formatDate(new Date(CREATION_TIME));
|
|
|
+ document.getElementById("expiralTime").textContent = formatDate(new Date(EXPIRAL_TIME));
|
|
|
})();
|
|
|
|