var FinishedUpload = /** @class */ (function () {
function FinishedUpload() {
}
return FinishedUpload;
}());
var uploader = null;
var finishedUploads = new Array();
var totalUploads = 0;
var UploadProgressBar = /** @class */ (function () {
function UploadProgressBar(file) {
this.file = file;
this.name = file.name;
this.queueNum = totalUploads;
totalUploads++;
this.uploadDiv = document.createElement("a");
this.uploadDiv.setAttribute("class", "file_button");
this.uploadDiv.innerText = "Queued\n" + this.file.name;
this.uploadDivJQ = $(this.uploadDiv);
$("#uploads_queue").append(this.uploadDivJQ.hide().fadeIn('slow').css("display", ""));
}
UploadProgressBar.prototype.onProgress = function (progress) {
this.uploadDiv.innerText = "Uploading... " + Math.round(progress * 1000) / 10 + "%\n" + this.file.name;
this.uploadDiv.setAttribute('style', 'background: linear-gradient('
+ 'to right, '
+ 'var(--file_background_color) 0%, '
+ 'var(--highlight_color) ' + ((progress * 100)) + '%, '
+ 'var(--file_background_color) ' + ((progress * 100) + 1) + '%)');
};
UploadProgressBar.prototype.onFinished = function (id) {
finishedUploads[this.queueNum] = {
id: id,
name: this.file.name
};
this.uploadDiv.setAttribute('style', 'background: var(--file_background_color)');
this.uploadDiv.setAttribute('href', '/u/' + id);
this.uploadDiv.setAttribute("target", "_blank");
this.uploadDivJQ.html(''
+ this.file.name + '
'
+ '' + window.location.hostname + '/u/' + id + '');
};
UploadProgressBar.prototype.onFailure = function (response, error) {
this.uploadDiv.setAttribute('style', 'background: var(--danger_color)');
this.uploadDivJQ.html(this.file.name + '
'
+ 'Upload failed after three tries!
'
+ "Message: " + error);
};
return UploadProgressBar;
}());
function handleUploads(files) {
if (uploader === null) {
uploader = new UploadManager();
$("#uploads_queue").animate({ "height": "340px" }, { "duration": 2000, queue: false });
}
for (var i = 0; i < files.length; i++) {
uploader.uploadFile(new UploadProgressBar(files.item(i)));
}
}
// List creation
function createList(title, anonymous) {
if (uploader.uploading()) {
var cont = confirm("Some files have not finished uploading yet. Creating a list now " +
"will exclude those files.\n\nContinue?");
if (!cont) {
return;
}
}
var postData = {
"title": title,
"anonymous": anonymous,
"files": new Array()
};
for (var i = 0; i < finishedUploads.length; i++) {
postData.files.push({
"id": finishedUploads[i].id
});
}
$.ajax({
url: "/api/list",
contentType: "application/json",
method: "POST",
data: JSON.stringify(postData),
dataType: "json",
success: function (response) {
var resultString = "