Handle edge cases, aka why name is not a separate header
This commit is contained in:
parent
531ebd9cce
commit
5b9b7e3802
@ -23,7 +23,7 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.3.7 - 2014-02-15
|
* 4chan X - Version 1.3.7 - 2014-02-17
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
||||||
@ -5663,8 +5663,26 @@
|
|||||||
QR.handleFiles(files);
|
QR.handleFiles(files);
|
||||||
return $.addClass(QR.nodes.el, 'dump');
|
return $.addClass(QR.nodes.el, 'dump');
|
||||||
},
|
},
|
||||||
handleBlob: function(blob) {
|
handleBlob: function(urlBlob, header, url) {
|
||||||
var _ref;
|
var blob, end, endnl, endsc, mime, name, name_end, name_start, start, _ref;
|
||||||
|
name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
||||||
|
start = header.indexOf("Content-Type: ") + 14;
|
||||||
|
endsc = header.substr(start, header.length).indexOf(";");
|
||||||
|
endnl = header.substr(start, header.length).indexOf("\n") - 1;
|
||||||
|
end = endnl;
|
||||||
|
if (endsc !== -1 && endsc < endnl) {
|
||||||
|
end = endsc;
|
||||||
|
}
|
||||||
|
mime = header.substr(start, end);
|
||||||
|
blob = new Blob([urlBlob], {
|
||||||
|
type: mime
|
||||||
|
});
|
||||||
|
blob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
||||||
|
name_start = header.indexOf('name="') + 6;
|
||||||
|
if (name_start - 6 !== -1) {
|
||||||
|
name_end = header.substr(name_start, header.length).indexOf('"');
|
||||||
|
blob.name = header.substr(name_start, name_end);
|
||||||
|
}
|
||||||
if (blob.type === null) {
|
if (blob.type === null) {
|
||||||
return QR.error("Unsupported file type.");
|
return QR.error("Unsupported file type.");
|
||||||
}
|
}
|
||||||
@ -5684,7 +5702,7 @@
|
|||||||
url: url,
|
url: url,
|
||||||
overrideMimeType: "text/plain; charset=x-user-defined",
|
overrideMimeType: "text/plain; charset=x-user-defined",
|
||||||
onload: function(xhr) {
|
onload: function(xhr) {
|
||||||
var data, end, header, i, mime, r, start, urlBlob;
|
var data, i, r;
|
||||||
r = xhr.responseText;
|
r = xhr.responseText;
|
||||||
data = new Uint8Array(r.length);
|
data = new Uint8Array(r.length);
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -5692,18 +5710,7 @@
|
|||||||
data[i] = r.charCodeAt(i);
|
data[i] = r.charCodeAt(i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
header = xhr.responseHeaders;
|
QR.handleBlob(data, xhr.responseHeaders, url);
|
||||||
start = header.indexOf("Content-Type: ") + 14;
|
|
||||||
end = header.substr(start, header.length).indexOf("\n") - 1;
|
|
||||||
mime = header.substr(start, end);
|
|
||||||
if (mime === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
urlBlob = new Blob([data], {
|
|
||||||
type: mime
|
|
||||||
});
|
|
||||||
urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
|
||||||
QR.handleBlob(urlBlob);
|
|
||||||
return;
|
return;
|
||||||
return {
|
return {
|
||||||
onerror: function(xhr) {
|
onerror: function(xhr) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript
|
// Generated by CoffeeScript
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.3.7 - 2014-02-15
|
* 4chan X - Version 1.3.7 - 2014-02-17
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
||||||
@ -5675,8 +5675,26 @@
|
|||||||
QR.handleFiles(files);
|
QR.handleFiles(files);
|
||||||
return $.addClass(QR.nodes.el, 'dump');
|
return $.addClass(QR.nodes.el, 'dump');
|
||||||
},
|
},
|
||||||
handleBlob: function(blob) {
|
handleBlob: function(urlBlob, header, url) {
|
||||||
var _ref;
|
var blob, end, endnl, endsc, mime, name, name_end, name_start, start, _ref;
|
||||||
|
name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
||||||
|
start = header.indexOf("Content-Type: ") + 14;
|
||||||
|
endsc = header.substr(start, header.length).indexOf(";");
|
||||||
|
endnl = header.substr(start, header.length).indexOf("\n") - 1;
|
||||||
|
end = endnl;
|
||||||
|
if (endsc !== -1 && endsc < endnl) {
|
||||||
|
end = endsc;
|
||||||
|
}
|
||||||
|
mime = header.substr(start, end);
|
||||||
|
blob = new Blob([urlBlob], {
|
||||||
|
type: mime
|
||||||
|
});
|
||||||
|
blob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
||||||
|
name_start = header.indexOf('name="') + 6;
|
||||||
|
if (name_start - 6 !== -1) {
|
||||||
|
name_end = header.substr(name_start, header.length).indexOf('"');
|
||||||
|
blob.name = header.substr(name_start, name_end);
|
||||||
|
}
|
||||||
if (blob.type === null) {
|
if (blob.type === null) {
|
||||||
return QR.error("Unsupported file type.");
|
return QR.error("Unsupported file type.");
|
||||||
}
|
}
|
||||||
@ -5695,13 +5713,8 @@
|
|||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
xhr.responseType = 'blob';
|
xhr.responseType = 'blob';
|
||||||
xhr.onload = function(e) {
|
xhr.onload = function(e) {
|
||||||
var urlBlob;
|
|
||||||
if (this.readyState === this.DONE && xhr.status === 200) {
|
if (this.readyState === this.DONE && xhr.status === 200) {
|
||||||
urlBlob = new Blob([this.response], {
|
QR.handleBlob(urlBlob, this.getResponseHeaders('Content-Type'), url);
|
||||||
type: this.getResponseHeader('content-type')
|
|
||||||
});
|
|
||||||
urlBlob.name = url.substr(url.lastIndexOf('/') + 1, url.length);
|
|
||||||
QR.handleBlob(urlBlob);
|
|
||||||
} else {
|
} else {
|
||||||
QR.error("Can't load image.");
|
QR.error("Can't load image.");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user