Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- (function() {
- var tmp;
- var options;
- var done;
- var download;
- var r;
- var elem;
- var err;
- var ca;
- var $;
- var sum;
- var success;
- var boxChild;
- var J;
- var add;
- var yw;
- var times;
- var total;
- var count;
- var title;
- var Peer;
- var progressElement;
- var SessionDescription;
- var aminoAcidSpan;
- var response;
- var div;
- var digitPar;
- var y;
- var yi;
- options = {
- iceServers : [{
- url : "stun:stun01.sipphone.com"
- }, {
- url : "stun:stun.ekiga.net"
- }, {
- url : "stun:stun.fwdnet.net"
- }, {
- url : "stun:stun.ideasip.com"
- }, {
- url : "stun:stun.iptel.org"
- }, {
- url : "stun:stun.rixtelecom.se"
- }, {
- url : "stun:stun.schlund.de"
- }, {
- url : "stun:stun.l.google.com:19302"
- }, {
- url : "stun:stun1.l.google.com:19302"
- }, {
- url : "stun:stun2.l.google.com:19302"
- }, {
- url : "stun:stun3.l.google.com:19302"
- }, {
- url : "stun:stun4.l.google.com:19302"
- }, {
- url : "stun:stunserver.org"
- }, {
- url : "stun:stun.softjoys.com"
- }, {
- url : "stun:stun.voiparound.com"
- }, {
- url : "stun:stun.voipbuster.com"
- }, {
- url : "stun:stun.voipstunt.com"
- }, {
- url : "stun:stun.voxgratia.org"
- }]
- };
- /**
- * @param {number} value
- * @return {?}
- */
- ca = function(value) {
- return 1E9 < value ? Math.round(value / 1E7) / 100 + " GBps" : 1E6 < value ? Math.round(value / 1E4) / 100 + " MBps" : 1E3 < value ? Math.round(value / 10) / 100 + " KBps" : Math.round(value) + " Bps";
- };
- /**
- * @param {number} t
- * @return {?}
- */
- $ = function(t) {
- return 86400 < t ? "More than 24 hours" : 3600 < t ? Math.floor(t / 3600) + " hour(s) and " + Math.floor(t / 60 % 60) + " minute(s)" : 60 < t ? Math.floor(t / 60) + " minute(s) and " + Math.floor(t % 60) + " second(s)" : Math.floor(t) + " second(s)";
- };
- /** @type {(Element|null)} */
- elem = document.getElementById("dropzone");
- /** @type {(Element|null)} */
- response = document.getElementById("status");
- /** @type {(Element|null)} */
- div = document.getElementById("substatus");
- /** @type {(Element|null)} */
- digitPar = document.getElementById("subsubstatus");
- /** @type {(Element|null)} */
- title = document.getElementById("password");
- /** @type {(Element|null)} */
- download = document.getElementById("download");
- /** @type {(Element|null)} */
- r = document.getElementById("download2");
- /** @type {(Element|null)} */
- boxChild = document.getElementById("hud");
- /** @type {(Element|null)} */
- aminoAcidSpan = document.getElementById("speed");
- /** @type {(Element|null)} */
- tmp = document.getElementById("ETA");
- /** @type {(Element|null)} */
- progressElement = document.getElementById("progress");
- Peer = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.msRTCPeerConnection;
- SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription || ["window.msRTCSessionDescription"];
- if (!(Peer && SessionDescription)) {
- /** @type {string} */
- elem.style.display = "none";
- /** @type {string} */
- response.innerHTML = "Your browser is not supported, consider downloading Chrome.";
- }
- if ("/" !== window.location.href[window.location.href.length - 1]) {
- /** @type {string} */
- elem.style.display = "none";
- /** @type {string} */
- title.style.display = "block";
- }
- elem.addEventListener("dragover", function(event) {
- event.stopPropagation();
- event.preventDefault();
- return elem.style["background-color"] = "#ddd";
- });
- elem.addEventListener("dragexit", function(event) {
- event.stopPropagation();
- return event.preventDefault();
- });
- elem.addEventListener("drop", function(event) {
- event.stopPropagation();
- event.preventDefault();
- /** @type {string} */
- elem.style["background-color"] = "";
- return window.ship(event.dataTransfer.files);
- });
- /** @type {null} */
- err = done = null;
- /** @type {number} */
- yw = yi = y = 0;
- /** @type {boolean} */
- J = false;
- /** @type {!Array} */
- times = [];
- /** @type {number} */
- count = sum = total = 0;
- /** @type {string} */
- progressElement.style.width = "0";
- /**
- * @return {undefined}
- */
- add = function() {
- /** @type {number} */
- yw = yi = y = 0;
- /** @type {boolean} */
- J = false;
- /** @type {!Array} */
- times = [];
- /** @type {number} */
- count = sum = total = 0;
- /** @type {string} */
- progressElement.style.width = "0";
- };
- /**
- * @return {?}
- */
- success = function() {
- if (J) {
- times.unshift(yi - yw);
- if (0 === times[0]) {
- if (count = count + 1, 10 < count) {
- /** @type {string} */
- err = "Disconnected unexpectedly";
- done();
- /** @type {boolean} */
- J = false;
- return;
- }
- } else {
- /** @type {number} */
- count = 0;
- }
- yw = yi;
- sum = sum + times[0];
- if (30 < times.length) {
- /** @type {number} */
- sum = sum - times[30];
- }
- total = total + times[0];
- if (60 < times.length) {
- /** @type {number} */
- total = total - times.pop();
- }
- /** @type {number} */
- var i = .1 * times[0] + .2 * sum / Math.min(30, times.length) + .7 * total / Math.min(60, times.length);
- /** @type {number} */
- var h = (y - yi) / i;
- aminoAcidSpan.innerHTML = ca(i);
- tmp.innerHTML = $(h);
- /** @type {string} */
- progressElement.style.width = Math.round(100 * yi / y) + "%";
- return setTimeout(success, 1E3);
- }
- };
- /**
- * @param {!NodeList} body
- * @return {?}
- */
- window.ship = function(body) {
- var tmp;
- /** @type {string} */
- response.innerHTML = "Generating Link, Please Wait...";
- /** @type {string} */
- div.innerHTML = "";
- /** @type {string} */
- div.style.display = "inline-block";
- /** @type {string} */
- elem.style.display = "none";
- /** @type {null} */
- var data = null;
- /** @type {boolean} */
- var t = false;
- var peer = new Peer(options);
- var channel = peer.createDataChannel("data");
- /** @type {string} */
- channel.binaryType = "arraybuffer";
- /** @type {boolean} */
- var actual = tmp = false;
- /** @type {string} */
- err = "Connection closed";
- /** @type {number} */
- channel.bufferedAmountLowThreshold = 5E6;
- /** @type {number} */
- var start = 0;
- /** @type {!Array} */
- var u = [];
- /** @type {!Array} */
- var keys = [];
- /** @type {!Array} */
- var _sizeAnimateTimeStamps = [];
- /** @type {null} */
- var r = null;
- /** @type {number} */
- var i = 0;
- /** @type {number} */
- var testHtml = -2;
- add();
- /**
- * @param {?} positionError
- * @return {?}
- */
- var fail = function(positionError) {
- return console.log(positionError);
- };
- /**
- * @return {?}
- */
- var send = function() {
- if (!tmp && (actual || "complete" === peer.iceGatheringState)) {
- /** @type {!XMLHttpRequest} */
- var xhr = new XMLHttpRequest;
- xhr.open("POST", "/link", true);
- xhr.setRequestHeader("Content-Type", "application/json");
- /**
- * @return {?}
- */
- xhr.onload = function() {
- if (4 === xhr.readyState) {
- if (200 !== xhr.status) {
- response.innerHTML(xhr.responseText);
- } else {
- /** @type {*} */
- var file = JSON.parse(xhr.responseText);
- data = file.password;
- /** @type {string} */
- response.innerHTML = "Leave the tab open and share the URL...";
- /** @type {string} */
- div.innerHTML = "<p><u><b>Download URL</b></u>: " + (window.location.href + file.link) + "</p>\n<p><u><b>Password</b></u>: " + data + "</p>";
- /**
- * @return {?}
- */
- var done = function() {
- /** @type {!XMLHttpRequest} */
- xhr = new XMLHttpRequest;
- /** @type {number} */
- xhr.timeout = 5E3;
- xhr.open("GET", "/link?id=" + file.link + "&password=" + data, true);
- xhr.setRequestHeader("Content-Type", "application/json");
- /**
- * @return {?}
- */
- xhr.ontimeout = function() {
- return done();
- };
- /**
- * @return {?}
- */
- xhr.onload = function() {
- var sdp;
- if (4 === xhr.readyState) {
- if (200 !== xhr.status) {
- response.innerHTML = xhr.responseText;
- } else {
- return (sdp = JSON.parse(xhr.responseText).answer) ? peer.setRemoteDescription(new SessionDescription(sdp)) : setTimeout(done, 2500);
- }
- }
- };
- return xhr.send();
- };
- return done();
- }
- }
- };
- xhr.send(JSON.stringify(peer.localDescription));
- return tmp = true;
- }
- };
- /**
- * @return {?}
- */
- var set = function() {
- var _results;
- /** @type {!Array} */
- _results = [];
- for (; 0 < keys.length && 15E6 > channel.bufferedAmount;) {
- var chunk = keys.shift();
- channel.send(chunk);
- if ("string" !== typeof chunk) {
- _results.push(start = start - chunk.byteLength);
- } else {
- testHtml = testHtml + 1;
- _results.push(div.innerHTML = testHtml + " files sent so far");
- }
- }
- return _results;
- };
- /**
- * @return {?}
- */
- var init = function() {
- var exports;
- /** @type {!Array} */
- exports = [];
- for (; 0 < u.length && 125E6 > start;) {
- var dir = u.shift();
- exports.push(function(file) {
- /** @type {!FileReader} */
- var reader = new FileReader;
- /**
- * @return {?}
- */
- reader.onload = function() {
- var _l;
- var timeoutIndex;
- keys.push(JSON.stringify({
- name : file.name,
- size : file.size,
- type : file.type
- }));
- /** @type {!Array} */
- var _results = [];
- /** @type {number} */
- var bookmarkedArrayMaxLength = _l = 0;
- /** @type {number} */
- timeoutIndex = Math.ceil(reader.result.byteLength / 16E3) - 1;
- for (; 0 <= timeoutIndex ? _l <= timeoutIndex : _l >= timeoutIndex; bookmarkedArrayMaxLength = 0 <= timeoutIndex ? ++_l : --_l) {
- _results.push(keys.push(reader.result.slice(16E3 * bookmarkedArrayMaxLength, 16E3 * (bookmarkedArrayMaxLength + 1))));
- }
- return _results;
- };
- /**
- * @return {?}
- */
- reader.onerror = function() {
- /** @type {string} */
- err = "Failed to read file";
- return channel.close();
- };
- reader.readAsArrayBuffer(file);
- return start = start + file.size;
- }(dir));
- }
- return exports;
- };
- /**
- * @return {?}
- */
- var loadFile = function() {
- var res;
- /** @type {!Array} */
- res = [];
- for (; (r || 0 < _sizeAnimateTimeStamps.length) && 125E6 > start;) {
- if (!r) {
- r = _sizeAnimateTimeStamps.shift();
- /** @type {number} */
- i = 0;
- keys.push(JSON.stringify({
- name : r.name,
- size : r.size,
- type : r.type
- }));
- }
- /** @type {!FileReader} */
- var reader = new FileReader;
- /**
- * @return {?}
- */
- reader.onload = function() {
- var _l;
- var timeoutIndex;
- /** @type {!Array} */
- var _results = [];
- /** @type {number} */
- var bookmarkedArrayMaxLength = _l = 0;
- /** @type {number} */
- timeoutIndex = Math.ceil(reader.result.byteLength / 16E3) - 1;
- for (; 0 <= timeoutIndex ? _l <= timeoutIndex : _l >= timeoutIndex; bookmarkedArrayMaxLength = 0 <= timeoutIndex ? ++_l : --_l) {
- _results.push(keys.push(reader.result.slice(16E3 * bookmarkedArrayMaxLength, 16E3 * (bookmarkedArrayMaxLength + 1))));
- }
- return _results;
- };
- /**
- * @return {?}
- */
- reader.onerror = function() {
- /** @type {string} */
- err = "Failed to read file";
- return channel.close();
- };
- var blob = r.slice(125E6 * i, 125E6 * (i + 1));
- reader.readAsArrayBuffer(blob);
- start = start + blob.size;
- if (i === Math.ceil(r.size / 125E6) - 1) {
- res.push(r = null);
- } else {
- res.push(i = i + 1);
- }
- }
- return res;
- };
- /**
- * @return {?}
- */
- var getInnerText = function() {
- if (0 < keys.length) {
- set();
- }
- if (9E7 > start) {
- if (0 < u.length) {
- return init();
- }
- if (0 < _sizeAnimateTimeStamps.length || r) {
- return loadFile();
- }
- if (0 === keys.length) {
- /**
- * @return {?}
- */
- var flush = function() {
- return 0 === channel.bufferedAmount && null !== data ? (data = null, testHtml = testHtml + 1, div.innerHTML = testHtml + " files sent", setTimeout(function() {
- return channel.close();
- }, 1E3)) : setTimeout(flush, 100);
- };
- return flush();
- }
- }
- };
- /**
- * @return {?}
- */
- done = function() {
- peer.close();
- /** @type {string} */
- elem.style.display = "";
- response.innerHTML = err + ". Send more?";
- /** @type {string} */
- boxChild.style.display = "";
- /** @type {string} */
- digitPar.style.display = "";
- return J = false;
- };
- /** @type {function(): ?} */
- channel.onbufferedamountlow = getInnerText;
- /**
- * @return {?}
- */
- channel.onopen = function() {
- return response.innerHTML = "Waiting for the password...";
- };
- /**
- * @param {!Object} e
- * @return {?}
- */
- channel.onmessage = function(e) {
- var end;
- if (!t) {
- if (data !== e.data) {
- channel.close();
- } else {
- /** @type {boolean} */
- t = true;
- /** @type {string} */
- response.innerHTML = "Sending files...";
- /** @type {string} */
- div.innerHTML = "";
- /** @type {number} */
- var i = 0;
- end = body.length;
- for (; i < end; i++) {
- e = body[i];
- y = y + e.size;
- if (125E6 > e.size) {
- u.push(e);
- } else {
- _sizeAnimateTimeStamps.push(e);
- }
- }
- keys.push("" + y);
- if (0 < u.length) {
- init();
- } else {
- loadFile();
- }
- return setTimeout(function() {
- return getInnerText();
- }, 3E3);
- }
- }
- };
- /** @type {function(): ?} */
- channel.onclose = done;
- /**
- * @param {?} line
- * @return {?}
- */
- channel.onerror = function(line) {
- return console.log(line);
- };
- /**
- * @param {!Object} state
- * @return {?}
- */
- peer.onicecandidate = function(state) {
- return null === state || "complete" === peer.iceGatheringState ? send() : actual = true;
- };
- return peer.createOffer(function(sdp) {
- return peer.setLocalDescription(sdp, function() {
- return setTimeout(send, 3E3);
- }, fail);
- }, fail);
- };
- /**
- * @return {undefined}
- */
- window.auth = function() {
- /** @type {string} */
- title.style.display = "";
- /** @type {string} */
- response.innerHTML = "Verifying password...";
- /** @type {string} */
- div.style.display = "inline-block";
- /** @type {string} */
- div.innerHTML = "";
- /** @type {string} */
- digitPar.innerHTML = "";
- var query = document.getElementById("passwordInput").value;
- /** @type {!XMLHttpRequest} */
- var xhr = new XMLHttpRequest;
- xhr.open("GET", "/link?id=" + window.location.href.substr(window.location.href.lastIndexOf("/") + 1) + "&password=" + query, true);
- xhr.setRequestHeader("Content-Type", "application/json");
- /**
- * @return {?}
- */
- xhr.onload = function() {
- var head;
- if (4 === xhr.readyState) {
- if (401 === xhr.status) {
- /** @type {string} */
- title.style.display = "block";
- /** @type {string} */
- response.innerHTML = "";
- div.innerHTML = xhr.responseText;
- } else {
- if (200 !== xhr.status) {
- response.innerHTML = xhr.responseText;
- } else {
- /** @type {string} */
- response.innerHTML = "Connecting...";
- var peer = new Peer(options);
- /** @type {null} */
- var channel = null;
- /** @type {boolean} */
- var h = head = false;
- /** @type {string} */
- err = "Connection closed";
- /** @type {null} */
- var file = null;
- /** @type {number} */
- var size = 0;
- /** @type {!Array} */
- var parts = [];
- /** @type {number} */
- var b = 1;
- /** @type {number} */
- var count = 0;
- /** @type {boolean} */
- var n = false;
- /** @type {number} */
- var testHtml = 0;
- add();
- /**
- * @param {?} area
- * @return {?}
- */
- var error = function(area) {
- return console.log(area);
- };
- /**
- * @return {?}
- */
- done = function() {
- peer.close();
- response.innerHTML = "" + err;
- div.innerHTML = testHtml + " files received";
- /** @type {string} */
- boxChild.style.display = "";
- /** @type {string} */
- digitPar.style.display = "";
- return J = false;
- };
- /**
- * @return {?}
- */
- var send = function() {
- if (!head && (h || "complete" === peer.iceGatheringState)) {
- return xhr = new XMLHttpRequest, xhr.open("PUT", "/link?id=" + window.location.href.substr(window.location.href.lastIndexOf("/") + 1) + "&password=" + query, true), xhr.setRequestHeader("Content-Type", "application/json"), xhr.onload = function() {
- if (4 === xhr.readyState) {
- if (204 !== xhr.status) {
- response.innerHTML = xhr.responseText;
- } else {
- return response.innerHTML = "Connecting...";
- }
- }
- }, xhr.send(JSON.stringify(peer.localDescription)), head = true;
- }
- };
- /**
- * @param {!Object} event
- * @return {?}
- */
- peer.ondatachannel = function(event) {
- channel = event.channel;
- /**
- * @return {?}
- */
- channel.onopen = function() {
- /** @type {string} */
- channel.binaryType = "arraybuffer";
- channel.send(query);
- return response.innerHTML = "Receiving files...";
- };
- /**
- * @param {string} e
- * @return {?}
- */
- channel.onmessage = function(e) {
- if (y) {
- if (file) {
- parts.push(e.data);
- yi = yi + e.data.byteLength;
- size = size + e.data.byteLength;
- count = count + e.data.byteLength;
- if (size === file.size) {
- /** @type {!Blob} */
- var blob = new Blob(parts, {
- type : file.type
- });
- var url = window.URL.createObjectURL(blob);
- download.href = url;
- /** @type {string} */
- download.download = 1 === b ? file.name : file.name + ("." + b + ".piece");
- download.click();
- setTimeout(function(old_url) {
- window.URL.revokeObjectURL(old_url);
- return blob = null;
- }, 1E3, url);
- testHtml = testHtml + 1;
- /** @type {string} */
- div.innerHTML = testHtml + " files received so far";
- /** @type {null} */
- file = null;
- /** @type {number} */
- count = size = 0;
- /** @type {number} */
- b = 1;
- /** @type {boolean} */
- n = false;
- return parts = [];
- }
- if (45E7 < count && (digitPar.innerHTML = "Some files were split since they are too big to be saved in one piece, use the combiner script to combine them back into one file.", blob = new Blob(parts, {
- type : file.type
- }), url = window.URL.createObjectURL(blob), download.href = url, e = 10 > b ? "0" + b : b, download.download = file.name + ("." + e + ".piece"), b = b + 1, download.click(), setTimeout(function(old_url) {
- window.URL.revokeObjectURL(old_url);
- return blob = null;
- }, 1E3, url), count = 0, parts = [], !n)) {
- /** @type {null} */
- var script = null;
- /** @type {!Blob} */
- script = -1 !== window.navigator.userAgent.indexOf("Windows") ? new Blob(["COPY /b " + file.name + "*.piece " + file.name + "\r\nDEL " + file.name + '*.piece\r\nDEL "%~f0"'], {
- type : "application/bat"
- }) : new Blob(["#!/bin/sh\ncat " + file.name + "*.piece > " + file.name + "\nrm -f " + file.name + '*.piece\nrm -- "$0"'], {
- type : "application/x-sh"
- });
- e = window.URL.createObjectURL(script);
- /** @type {string} */
- r.href = e;
- /** @type {string} */
- r.download = file.name + ".combiner." + (-1 !== window.navigator.userAgent.indexOf("Windows") ? "bat" : "sh");
- r.click();
- setTimeout(function(old_url) {
- window.URL.revokeObjectURL(old_url);
- return script = null;
- }, 1E3, e);
- return n = true;
- }
- } else {
- return file = JSON.parse(e.data);
- }
- } else {
- return y = +e.data, boxChild.style.display = "inline-block", digitPar.style.display = "inline-block", div.innerHTML = testHtml + " files received so far", J = true, success();
- }
- };
- channel.onclose = done;
- return channel.onerror = function(line) {
- return console.log(line);
- };
- };
- /**
- * @param {!Object} state
- * @return {?}
- */
- peer.onicecandidate = function(state) {
- return null === state || "complete" === peer.iceGatheringState ? send() : h = true;
- };
- return peer.setRemoteDescription(new SessionDescription(JSON.parse(xhr.responseText).offer), function() {
- return peer.createAnswer(function(sdp) {
- return peer.setLocalDescription(sdp, function() {
- return setTimeout(send, 3E3);
- }, error);
- }, error);
- }, error);
- }
- }
- }
- };
- xhr.send();
- };
- }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment