summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php90
1 files changed, 63 insertions, 27 deletions
diff --git a/index.php b/index.php
index 464433a..6dad5eb 100644
--- a/index.php
+++ b/index.php
@@ -145,12 +145,27 @@
document.getElementById("main").style.display = "none";
}
+ window.onblur = () => {
+ if (!window.fileID && !window.file) return;
+ window.oldTitle = document.title;
+ document.title = document.getElementById("rfile-status").innerText;
+ window.infoInTitle = true;
+ }
+
+ window.onfocus = () => {
+ if (!window.fileID && !window.file) return;
+ window.infoInTitle = false;
+ document.title = window.oldTitle;
+ }
+
window.currentID = null;
window.currentSpeed = 0;
window.maxSpeed = <?= getLimits()['speed'] ?> / 2;
window.file = null;
window.keyChain = null;
window.forceQuit = false;
+ window.infoInTitle = false;
+ window.oldTitle = document.title;
function formatSize(size) {
if (size > 1024) {
@@ -178,6 +193,14 @@
document.getElementById("file-name").innerText = file.name;
document.getElementById("file-size").innerText = formatSize(file.size);
+ if (file.size > <?= getLimits()["size"] ?>) {
+ alert("This file is too large. The maximum allowed size with your plan is <?= sizeToString(getLimits()["size"]) ?>. Please try a smaller file.");
+ window.file = null;
+ return;
+ }
+
+ document.title = window.oldTitle = file.name + " | " + document.title;
+
document.getElementById("main").style.display = "none";
document.getElementById("share").style.display = "";
canResume = true;
@@ -237,7 +260,15 @@
}
}
- return (up ? "↑ " : "↓ ") + formatSize(currentSpeed) + "/s · " + formatSize(done) + "/" + formatSize(total) + (etaString ? (" · " + etaString) : "");
+ let info = (up ? "↑ " : "↓ ") + formatSize(currentSpeed) + "/s · " + formatSize(done) + "/" + formatSize(total) + (etaString ? (" · " + etaString) : "");
+
+ if (window.infoInTitle) {
+ document.title = info;
+ } else {
+ document.title = window.oldTitle;
+ }
+
+ return info;
}
let lastChunk;
@@ -299,33 +330,38 @@
if (data.type !== "encrypted" && data.type !== "encryptedData") console.log(data);
if (data.type === "encryptedData") {
- BridleshareCrypt.decryptBuffer(data.message, keyChain.chain).then((ab) => {
- blob = new Blob([blob, ab], {
- type: window.fileType
- });
-
- totalReceived = totalReceived + ab.byteLength;
- let total = window.fileSize;
- let percentage = (totalReceived / total) * 100;
-
- if (lastChunk) {
- currentSpeed = ab.byteLength / ((new Date().getTime() / 1000) - lastChunk);
- lastChunk = new Date().getTime() / 1000;
- } else {
- lastChunk = new Date().getTime() / 1000;
- }
-
- document.getElementById("receive-progress").className = "progress-bar bg-primary";
- document.getElementById("receive-error").style.display = document.getElementById("share-error").style.display = "none";
- document.getElementById("receive-progress").style.width = percentage + "%";
- document.getElementById("rfile-status").innerText = generateStatus(false, totalReceived, total);
-
- if (connected) {
- pos++;
+ let waiter = setInterval(() => {
+ if (keyChain.chain) {
+ clearInterval(waiter);
+ BridleshareCrypt.decryptBuffer(data.message, keyChain.chain).then((ab) => {
+ blob = new Blob([blob, ab], {
+ type: window.fileType
+ });
- sendEncrypted({
- type: "next",
- chunk: pos
+ totalReceived = totalReceived + ab.byteLength;
+ let total = window.fileSize;
+ let percentage = (totalReceived / total) * 100;
+
+ if (lastChunk) {
+ currentSpeed = ab.byteLength / ((new Date().getTime() / 1000) - lastChunk);
+ lastChunk = new Date().getTime() / 1000;
+ } else {
+ lastChunk = new Date().getTime() / 1000;
+ }
+
+ document.getElementById("receive-progress").className = "progress-bar bg-primary";
+ document.getElementById("receive-error").style.display = document.getElementById("share-error").style.display = "none";
+ document.getElementById("receive-progress").style.width = percentage + "%";
+ document.getElementById("rfile-status").innerText = generateStatus(false, totalReceived, total);
+
+ if (connected) {
+ pos++;
+
+ sendEncrypted({
+ type: "next",
+ chunk: pos
+ });
+ }
});
}
});