}
// Test if content can be previewed
- type = document.getElementById('file_select').files[0].type;
- if (type.indexOf("image") > -1 ||
- type.indexOf("audio") > -1 ||
- type.indexOf("text") > -1 ||
- type.indexOf("video") > -1)
- {
+ type = document.getElementById('file_select').files[0].type;
+ if ((type.startsWith('image/')
+ || type.startsWith('audio')
+ || type.startsWith('text/plain')
+ || type.startsWith('video/'))
+ && !type.includes('image/svg+xml'))
+ {
document.getElementById('preview_link').href = preview_link_href;
document.getElementById('preview_link_text').innerHTML = web_root + preview_link_href;
document.getElementById('upload_finished_preview').style.display = '';
- }
+ }
}
// Direct download link
}
}
+function XHRErrorHandler(e)
+{
+ var text = "${e.type}: ${e.loaded} bytes transferred"
+ console.log(text)
+}
+
function pop_failure (e)
{
- var text = "An error occured";
+ var text = "<p>An error occured";
if (typeof e !== 'undefined')
- text = e;
- text = "<p>" + text + "</p>";
+ text += ": " + e;
+ text += "</p>";
document.getElementById('error_pop').innerHTML = e;
document.getElementById('uploading').style.display = 'none';
var req = new XMLHttpRequest ();
req.upload.addEventListener ("progress", upload_progress, false);
- req.addEventListener ("error", pop_failure, false);
- req.addEventListener ("abort", pop_failure, false);
+ req.addEventListener ("error", XHRErrorHandler, false);
+ req.addEventListener ("abort", XHRErrorHandler, false);
req.onreadystatechange = function ()
{
if (req.readyState == 4 && req.status == 200)
async_global_time = time;
var req = new XMLHttpRequest ();
- req.addEventListener ("error", pop_failure, false);
- req.addEventListener ("abort", pop_failure, false);
+ req.addEventListener ("error", XHRErrorHandler, false);
+ req.addEventListener ("abort", XHRErrorHandler, false);
req.onreadystatechange = function ()
{
if (req.readyState == 4 && req.status == 200)
}
var req = new XMLHttpRequest ();
req.upload.addEventListener ("progress", async_upload_progress, false);
- req.addEventListener ("error", pop_failure, false);
- req.addEventListener ("abort", pop_failure, false);
+ req.addEventListener ("error", XHRErrorHandler, false);
+ req.addEventListener ("abort", XHRErrorHandler, false);
req.onreadystatechange = function ()
{
if (req.readyState == 4)
function async_upload_end (code)
{
var req = new XMLHttpRequest ();
- req.addEventListener ("error", pop_failure, false);
- req.addEventListener ("abort", pop_failure, false);
+ req.addEventListener ("error", XHRErrorHandler, false);
+ req.addEventListener ("abort", XHRErrorHandler, false);
req.onreadystatechange = function ()
{
if (req.readyState == 4 && req.status == 200)