diff options
author | RaindropsSys <contact@minteck.org> | 2023-07-07 22:08:59 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-07-07 22:08:59 +0200 |
commit | 2dd43d2822b6a4b0645e70afa0b7b3bad6321e15 (patch) | |
tree | e27f56df7b1b8c8d042b3d508191b5d18b712b69 | |
parent | e2c851245cb32f778d90f6ceee1f368d9248e2ad (diff) | |
download | bridleshare-2dd43d2822b6a4b0645e70afa0b7b3bad6321e15.tar.gz bridleshare-2dd43d2822b6a4b0645e70afa0b7b3bad6321e15.tar.bz2 bridleshare-2dd43d2822b6a4b0645e70afa0b7b3bad6321e15.zip |
Updated 2 files and added .idea/vcs.xml (automated)
-rw-r--r-- | .idea/vcs.xml | 6 | ||||
-rw-r--r-- | includes/ws/index.js | 8 | ||||
-rw-r--r-- | index.php | 90 |
3 files changed, 72 insertions, 32 deletions
diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project>
\ No newline at end of file diff --git a/includes/ws/index.js b/includes/ws/index.js index 61e61a3..ef4073d 100644 --- a/includes/ws/index.js +++ b/includes/ws/index.js @@ -71,13 +71,13 @@ wss.on('connection', function connection(ws, req) { if (ws.peer && data.message) { transmittedData += JSON.stringify(data.message).length; - if (transmittedData >= limits.size * 1.02) { + /*if (transmittedData >= limits.size * 1.02) { ws.send(JSON.stringify({ type: "error", error: "SIZE_LIMIT_EXCEEDED" })); ws.close(); - } + }*/ let delay = new Date().getTime() - ws.lastMessage > 0 ? Math.round((JSON.stringify(data.message).length / limits.speed) * 1000) : 0; @@ -135,9 +135,7 @@ wss.on('connection', function connection(ws, req) { ws.on('close', () => { if (ws.peer) { - ws.peer.send(JSON.stringify({ - type: "left" - })); + ws.peer.close(); } if (ws.id) delete users[ws.id]; @@ -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 + }); + } }); } }); |