Embed resources into templates
This commit is contained in:
@@ -89,39 +89,68 @@ function createList(title, anonymous) {
|
||||
"id": finishedUploads[i].id
|
||||
});
|
||||
}
|
||||
$.ajax({
|
||||
url: "/api/list",
|
||||
contentType: "application/json",
|
||||
method: "POST",
|
||||
data: JSON.stringify(postData),
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", apiEndpoint + "/list");
|
||||
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status == 200 || xhr.status == 0) {
|
||||
// Request is a success
|
||||
var resultString = "<div class=\"file_button\">"
|
||||
+ '<img src="' + apiEndpoint + '/list/' + response.id + '/thumbnail"/>'
|
||||
+ '<img src="' + apiEndpoint + '/list/' + xhr.response.id + '/thumbnail"/>'
|
||||
+ "List creation finished!<br/>"
|
||||
+ title + "<br/>"
|
||||
+ "<a href=\"/l/" + response.id + "\" target=\"_blank\">" + window.location.hostname + "/l/" + response.id + "</a>"
|
||||
+ "<a href=\"/l/" + xhr.response.id + "\" target=\"_blank\">" + window.location.hostname + "/l/" + xhr.response.id + "</a>"
|
||||
+ "</div>";
|
||||
$('#uploads_queue').append($(resultString).hide().fadeIn('slow').css("display", ""));
|
||||
$("#uploads_queue").animate({
|
||||
scrollTop: $("#uploads_queue").prop("scrollHeight")
|
||||
}, 1000);
|
||||
window.open('/l/' + response.id, '_blank');
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.log("xhr:");
|
||||
console.log(xhr);
|
||||
console.log("status:");
|
||||
console.log(status);
|
||||
console.log("error:");
|
||||
console.log(error);
|
||||
document.getElementById("uploads_queue").append(resultString);
|
||||
window.open('/l/' + xhr.response.id, '_blank');
|
||||
}
|
||||
else {
|
||||
console.log("status: " + xhr.status + " response: " + xhr.response);
|
||||
var resultString = "<div class=\"file_button\">List creation failed<br/>"
|
||||
+ "The server responded with this: <br/>"
|
||||
+ xhr.responseJSON.message
|
||||
+ xhr.response.message
|
||||
+ "</div>";
|
||||
$('#uploads_queue').append($(resultString).hide().fadeIn('slow').css("display", ""));
|
||||
document.getElementById("uploads_queue").append(resultString);
|
||||
}
|
||||
});
|
||||
};
|
||||
xhr.send(JSON.stringify(postData));
|
||||
// $.ajax({
|
||||
// url: "/api/list",
|
||||
// contentType: "application/json",
|
||||
// method: "POST",
|
||||
// data: JSON.stringify(postData),
|
||||
// dataType: "json",
|
||||
// success: function(response) {
|
||||
// var resultString = "<div class=\"file_button\">"
|
||||
// + '<img src="'+apiEndpoint+'/list/'+response.id+'/thumbnail"/>'
|
||||
// + "List creation finished!<br/>"
|
||||
// + title + "<br/>"
|
||||
// + "<a href=\"/l/" + response.id + "\" target=\"_blank\">"+window.location.hostname+"/l/" + response.id + "</a>"
|
||||
// + "</div>";
|
||||
// $('#uploads_queue').append(
|
||||
// $(resultString).hide().fadeIn('slow').css("display", "")
|
||||
// );
|
||||
// window.open('/l/'+response.id, '_blank');
|
||||
// },
|
||||
// error: function(xhr, status, error) {
|
||||
// console.log("xhr:");
|
||||
// console.log(xhr);
|
||||
// console.log("status:");
|
||||
// console.log(status);
|
||||
// console.log("error:");
|
||||
// console.log(error);
|
||||
// var resultString = "<div class=\"file_button\">List creation failed<br/>"
|
||||
// + "The server responded with this: <br/>"
|
||||
// + xhr.responseJSON.message
|
||||
// + "</div>";
|
||||
// $('#uploads_queue').append(
|
||||
// $(resultString).hide().fadeIn('slow').css("display", "")
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
}
|
||||
// Form upload handlers
|
||||
// Relay click event to hidden file field
|
||||
@@ -319,39 +348,35 @@ var UploadWorker = /** @class */ (function () {
|
||||
};
|
||||
UploadWorker.prototype.upload = function (file) {
|
||||
console.debug("Starting upload of " + file.name);
|
||||
var that = this; // jquery changes the definiton of "this"
|
||||
var formData = new FormData();
|
||||
formData.append("name", file.name);
|
||||
formData.append('file', file.file);
|
||||
var that = this; // jquery changes the definiton of "this"
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: apiEndpoint + "/file",
|
||||
data: formData,
|
||||
timeout: 21600000,
|
||||
cache: false,
|
||||
async: true,
|
||||
crossDomain: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
xhr: function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", function (evt) {
|
||||
if (evt.lengthComputable) {
|
||||
file.onProgress(evt.loaded / evt.total);
|
||||
}
|
||||
}, false);
|
||||
return xhr;
|
||||
},
|
||||
success: function (data) {
|
||||
file.onFinished(data.id);
|
||||
that.setHistoryCookie(data.id);
|
||||
console.log("Done: " + data.id);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", apiEndpoint + "/file");
|
||||
xhr.timeout = 21600000; // 6 hours, to account for slow connections
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
// Update progess bar on progress
|
||||
xhr.onprogress = function (evt) {
|
||||
if (evt.lengthComputable) {
|
||||
file.onProgress(evt.loaded / evt.total);
|
||||
}
|
||||
};
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status == 200 || xhr.status == 0) {
|
||||
// Request is a success
|
||||
file.onFinished(xhr.response.id);
|
||||
that.setHistoryCookie(xhr.response.id);
|
||||
console.log("Done: " + xhr.response.id);
|
||||
that.newFile(); // Continue uploading on this thread
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.log("status: " + status + " error: " + error);
|
||||
}
|
||||
else {
|
||||
console.log("status: " + xhr.status + " response: " + xhr.response);
|
||||
if (that.tries === 3) {
|
||||
file.onFailure(status, error);
|
||||
file.onFailure(xhr.response.value, xhr.response.message);
|
||||
setTimeout(function () { that.newFile(); }, 2000); // Try to continue
|
||||
return; // Upload failed
|
||||
}
|
||||
@@ -359,7 +384,45 @@ var UploadWorker = /** @class */ (function () {
|
||||
that.tries++;
|
||||
setTimeout(function () { that.upload(file); }, that.tries * 3000);
|
||||
}
|
||||
});
|
||||
};
|
||||
xhr.send(formData);
|
||||
// $.ajax({
|
||||
// type: 'POST',
|
||||
// url: apiEndpoint+"/file",
|
||||
// data: formData,
|
||||
// timeout: 21600000, // 6 hours, to account for slow connections
|
||||
// cache: false,
|
||||
// async: true,
|
||||
// crossDomain: false,
|
||||
// contentType: false,
|
||||
// processData: false,
|
||||
// xhr: function () {
|
||||
// var xhr = new XMLHttpRequest();
|
||||
// xhr.upload.addEventListener("progress", function (evt) {
|
||||
// if (evt.lengthComputable) {
|
||||
// file.onProgress(evt.loaded / evt.total)
|
||||
// }
|
||||
// }, false);
|
||||
// return xhr;
|
||||
// },
|
||||
// success: function (data) {
|
||||
// file.onFinished(data.id)
|
||||
// that.setHistoryCookie(data.id)
|
||||
// console.log("Done: " + data.id)
|
||||
// that.newFile() // Continue uploading on this thread
|
||||
// },
|
||||
// error: function (xhr, status, error){
|
||||
// console.log("status: "+status+" error: "+error)
|
||||
// if (that.tries === 3) {
|
||||
// file.onFailure(status, error)
|
||||
// setTimeout(function(){that.newFile()}, 2000) // Try to continue
|
||||
// return; // Upload failed
|
||||
// }
|
||||
// // Try again
|
||||
// that.tries++
|
||||
// setTimeout(function(){that.upload(file)}, that.tries*3000)
|
||||
// }
|
||||
// });
|
||||
};
|
||||
UploadWorker.prototype.setHistoryCookie = function (id) {
|
||||
// Make sure the user is not logged in, for privacy. This keeps the
|
||||
|
Reference in New Issue
Block a user