smarter websocket url inference, show a full url for downloads

This commit is contained in:
xenofem 2022-04-27 21:47:36 -04:00
parent 9545ceb4f4
commit 7191b4df96

View file

@ -106,11 +106,11 @@ uploadButton.addEventListener('click', (e) => {
totalBytes = files.reduce((acc, file) => acc + file.size, 0);
socket = new WebSocket(`ws://${window.location.host}/upload`);
socket = new WebSocket(`${window.location.protocol === 'http:' ? 'ws' : 'wss'}://${window.location.host}/upload`);
socket.addEventListener('open', sendMetadata);
socket.addEventListener('message', (msg) => {
if (bytesSent === 0 && msg.data.match(/^[A-Za-z0-9]+$/)) {
downloadLink.textContent = msg.data;
downloadLink.textContent = `${window.location.origin}/download/${msg.data}`;
sendData();
} else if (msg.data === 'ack') {
sendData();