Fat arrows aren't needed here
This commit is contained in:
parent
d8b8028459
commit
2731e3c6eb
@ -6370,9 +6370,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleFile: function(file, index, nfiles) {
|
handleFile: function(file, index, nfiles) {
|
||||||
var isNewPost, max, post, _ref;
|
var isNewPost, isSingle, max, post, _ref;
|
||||||
|
isSingle = nfiles === 1;
|
||||||
if (/^text\//.test(file.type)) {
|
if (/^text\//.test(file.type)) {
|
||||||
if (nfiles === 1) {
|
if (isSingle) {
|
||||||
post = QR.selected;
|
post = QR.selected;
|
||||||
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) {
|
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) {
|
||||||
post = new QR.post();
|
post = new QR.post();
|
||||||
@ -6382,7 +6383,7 @@
|
|||||||
}
|
}
|
||||||
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
||||||
QR.error("" + file.name + ": Unsupported file type.");
|
QR.error("" + file.name + ": Unsupported file type.");
|
||||||
if (nfiles !== 1) {
|
if (!isSingle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6392,12 +6393,12 @@
|
|||||||
}
|
}
|
||||||
if (file.size > max) {
|
if (file.size > max) {
|
||||||
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
||||||
if (nfiles !== 1) {
|
if (!isSingle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isNewPost = false;
|
isNewPost = false;
|
||||||
if (nfiles === 1) {
|
if (isSingle) {
|
||||||
post = QR.selected;
|
post = QR.selected;
|
||||||
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) {
|
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) {
|
||||||
isNewPost = true;
|
isNewPost = true;
|
||||||
@ -6409,7 +6410,7 @@
|
|||||||
post.setFile(file);
|
post.setFile(file);
|
||||||
}
|
}
|
||||||
return QR.checkDimensions(file, function(pass) {
|
return QR.checkDimensions(file, function(pass) {
|
||||||
if (pass || nfiles === 1) {
|
if (pass || isSingle) {
|
||||||
return post.setFile(file);
|
return post.setFile(file);
|
||||||
} else if (isNewPost) {
|
} else if (isNewPost) {
|
||||||
return post.rm();
|
return post.rm();
|
||||||
@ -6420,72 +6421,66 @@
|
|||||||
var img, video;
|
var img, video;
|
||||||
if (/^image\//.test(file.type)) {
|
if (/^image\//.test(file.type)) {
|
||||||
img = new Image();
|
img = new Image();
|
||||||
img.onload = (function(_this) {
|
img.onload = function() {
|
||||||
return function() {
|
var height, pass, width;
|
||||||
var height, pass, width;
|
height = img.height, width = img.width;
|
||||||
height = img.height, width = img.width;
|
pass = true;
|
||||||
pass = true;
|
if (height > QR.max_height || width > QR.max_width) {
|
||||||
if (height > QR.max_height || width > QR.max_width) {
|
QR.error("" + file.name + ": Image too large (image: " + height + "x" + width + "px, max: " + QR.max_height + "x" + QR.max_width + "px)");
|
||||||
QR.error("" + file.name + ": Image too large (image: " + height + "x" + width + "px, max: " + QR.max_height + "x" + QR.max_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (height < QR.min_height || width < QR.min_width) {
|
||||||
if (height < QR.min_height || width < QR.min_width) {
|
QR.error("" + file.name + ": Image too small (image: " + height + "x" + width + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
||||||
QR.error("" + file.name + ": Image too small (image: " + height + "x" + width + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
return cb(pass);
|
||||||
return cb(pass);
|
};
|
||||||
};
|
|
||||||
})(this);
|
|
||||||
return img.src = URL.createObjectURL(file);
|
return img.src = URL.createObjectURL(file);
|
||||||
} else if (/^video\//.test(file.type)) {
|
} else if (/^video\//.test(file.type)) {
|
||||||
video = $.el('video');
|
video = $.el('video');
|
||||||
$.on(video, 'loadedmetadata', (function(_this) {
|
$.on(video, 'loadedmetadata', function() {
|
||||||
return function() {
|
var duration, max_height, max_width, pass, videoHeight, videoWidth;
|
||||||
var duration, max_height, max_width, pass, videoHeight, videoWidth;
|
if (!cb) {
|
||||||
if (cb == null) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
videoHeight = video.videoHeight, videoWidth = video.videoWidth, duration = video.duration;
|
||||||
videoHeight = video.videoHeight, videoWidth = video.videoWidth, duration = video.duration;
|
max_height = Math.min(QR.max_height, QR.max_height_video);
|
||||||
max_height = Math.min(QR.max_height, QR.max_height_video);
|
max_width = Math.min(QR.max_width, QR.max_width_video);
|
||||||
max_width = Math.min(QR.max_width, QR.max_width_video);
|
pass = true;
|
||||||
pass = true;
|
if (videoHeight > max_height || videoWidth > max_width) {
|
||||||
if (videoHeight > max_height || videoWidth > max_width) {
|
QR.error("" + file.name + ": Video too large (video: " + videoHeight + "x" + videoWidth + "px, max: " + max_height + "x" + max_width + "px)");
|
||||||
QR.error("" + file.name + ": Video too large (video: " + videoHeight + "x" + videoWidth + "px, max: " + max_height + "x" + max_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (videoHeight < QR.min_height || videoWidth < QR.min_width) {
|
||||||
if (videoHeight < QR.min_height || videoWidth < QR.min_width) {
|
QR.error("" + file.name + ": Video too small (video: " + videoHeight + "x" + videoWidth + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
||||||
QR.error("" + file.name + ": Video too small (video: " + videoHeight + "x" + videoWidth + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (!isFinite(video.duration)) {
|
||||||
if (!isFinite(video.duration)) {
|
QR.error("" + file.name + ": Video lacks duration metadata (try remuxing)");
|
||||||
QR.error("" + file.name + ": Video lacks duration metadata (try remuxing)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (duration > QR.max_duration_video) {
|
||||||
if (duration > QR.max_duration_video) {
|
QR.error("" + file.name + ": Video too long (video: " + duration + "s, max: " + QR.max_duration_video + "s)");
|
||||||
QR.error("" + file.name + ": Video too long (video: " + duration + "s, max: " + QR.max_duration_video + "s)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (video.mozHasAudio) {
|
||||||
if (video.mozHasAudio) {
|
QR.error("" + file.name + ": Audio not allowed");
|
||||||
QR.error("" + file.name + ": Audio not allowed");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
cb(pass);
|
||||||
cb(pass);
|
return cb = null;
|
||||||
return cb = null;
|
});
|
||||||
};
|
$.on(video, 'error', function() {
|
||||||
})(this));
|
var _ref;
|
||||||
$.on(video, 'error', (function(_this) {
|
if (!cb) {
|
||||||
return function() {
|
return;
|
||||||
var _ref;
|
}
|
||||||
if (cb == null) {
|
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) >= 0) {
|
||||||
return;
|
QR.error("" + file.name + ": Video appears corrupt");
|
||||||
}
|
}
|
||||||
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) >= 0) {
|
cb(false);
|
||||||
QR.error("" + file.name + ": Video appears corrupt");
|
return cb = null;
|
||||||
}
|
});
|
||||||
cb(false);
|
|
||||||
return cb = null;
|
|
||||||
};
|
|
||||||
})(this));
|
|
||||||
return video.src = URL.createObjectURL(file);
|
return video.src = URL.createObjectURL(file);
|
||||||
} else {
|
} else {
|
||||||
return cb(true);
|
return cb(true);
|
||||||
|
|||||||
@ -6428,9 +6428,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleFile: function(file, index, nfiles) {
|
handleFile: function(file, index, nfiles) {
|
||||||
var isNewPost, max, post, _ref;
|
var isNewPost, isSingle, max, post, _ref;
|
||||||
|
isSingle = nfiles === 1;
|
||||||
if (/^text\//.test(file.type)) {
|
if (/^text\//.test(file.type)) {
|
||||||
if (nfiles === 1) {
|
if (isSingle) {
|
||||||
post = QR.selected;
|
post = QR.selected;
|
||||||
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) {
|
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).com) {
|
||||||
post = new QR.post();
|
post = new QR.post();
|
||||||
@ -6440,7 +6441,7 @@
|
|||||||
}
|
}
|
||||||
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) < 0) {
|
||||||
QR.error("" + file.name + ": Unsupported file type.");
|
QR.error("" + file.name + ": Unsupported file type.");
|
||||||
if (nfiles !== 1) {
|
if (!isSingle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6450,12 +6451,12 @@
|
|||||||
}
|
}
|
||||||
if (file.size > max) {
|
if (file.size > max) {
|
||||||
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ").");
|
||||||
if (nfiles !== 1) {
|
if (!isSingle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isNewPost = false;
|
isNewPost = false;
|
||||||
if (nfiles === 1) {
|
if (isSingle) {
|
||||||
post = QR.selected;
|
post = QR.selected;
|
||||||
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) {
|
} else if (index !== 0 || (post = QR.posts[QR.posts.length - 1]).file) {
|
||||||
isNewPost = true;
|
isNewPost = true;
|
||||||
@ -6467,7 +6468,7 @@
|
|||||||
post.setFile(file);
|
post.setFile(file);
|
||||||
}
|
}
|
||||||
return QR.checkDimensions(file, function(pass) {
|
return QR.checkDimensions(file, function(pass) {
|
||||||
if (pass || nfiles === 1) {
|
if (pass || isSingle) {
|
||||||
return post.setFile(file);
|
return post.setFile(file);
|
||||||
} else if (isNewPost) {
|
} else if (isNewPost) {
|
||||||
return post.rm();
|
return post.rm();
|
||||||
@ -6478,68 +6479,62 @@
|
|||||||
var img, video;
|
var img, video;
|
||||||
if (/^image\//.test(file.type)) {
|
if (/^image\//.test(file.type)) {
|
||||||
img = new Image();
|
img = new Image();
|
||||||
img.onload = (function(_this) {
|
img.onload = function() {
|
||||||
return function() {
|
var height, pass, width;
|
||||||
var height, pass, width;
|
height = img.height, width = img.width;
|
||||||
height = img.height, width = img.width;
|
pass = true;
|
||||||
pass = true;
|
if (height > QR.max_height || width > QR.max_width) {
|
||||||
if (height > QR.max_height || width > QR.max_width) {
|
QR.error("" + file.name + ": Image too large (image: " + height + "x" + width + "px, max: " + QR.max_height + "x" + QR.max_width + "px)");
|
||||||
QR.error("" + file.name + ": Image too large (image: " + height + "x" + width + "px, max: " + QR.max_height + "x" + QR.max_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (height < QR.min_height || width < QR.min_width) {
|
||||||
if (height < QR.min_height || width < QR.min_width) {
|
QR.error("" + file.name + ": Image too small (image: " + height + "x" + width + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
||||||
QR.error("" + file.name + ": Image too small (image: " + height + "x" + width + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
return cb(pass);
|
||||||
return cb(pass);
|
};
|
||||||
};
|
|
||||||
})(this);
|
|
||||||
return img.src = URL.createObjectURL(file);
|
return img.src = URL.createObjectURL(file);
|
||||||
} else if (/^video\//.test(file.type)) {
|
} else if (/^video\//.test(file.type)) {
|
||||||
video = $.el('video');
|
video = $.el('video');
|
||||||
$.on(video, 'loadedmetadata', (function(_this) {
|
$.on(video, 'loadedmetadata', function() {
|
||||||
return function() {
|
var duration, max_height, max_width, pass, videoHeight, videoWidth;
|
||||||
var duration, max_height, max_width, pass, videoHeight, videoWidth;
|
if (!cb) {
|
||||||
if (cb == null) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
videoHeight = video.videoHeight, videoWidth = video.videoWidth, duration = video.duration;
|
||||||
videoHeight = video.videoHeight, videoWidth = video.videoWidth, duration = video.duration;
|
max_height = Math.min(QR.max_height, QR.max_height_video);
|
||||||
max_height = Math.min(QR.max_height, QR.max_height_video);
|
max_width = Math.min(QR.max_width, QR.max_width_video);
|
||||||
max_width = Math.min(QR.max_width, QR.max_width_video);
|
pass = true;
|
||||||
pass = true;
|
if (videoHeight > max_height || videoWidth > max_width) {
|
||||||
if (videoHeight > max_height || videoWidth > max_width) {
|
QR.error("" + file.name + ": Video too large (video: " + videoHeight + "x" + videoWidth + "px, max: " + max_height + "x" + max_width + "px)");
|
||||||
QR.error("" + file.name + ": Video too large (video: " + videoHeight + "x" + videoWidth + "px, max: " + max_height + "x" + max_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (videoHeight < QR.min_height || videoWidth < QR.min_width) {
|
||||||
if (videoHeight < QR.min_height || videoWidth < QR.min_width) {
|
QR.error("" + file.name + ": Video too small (video: " + videoHeight + "x" + videoWidth + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
||||||
QR.error("" + file.name + ": Video too small (video: " + videoHeight + "x" + videoWidth + "px, min: " + QR.min_height + "x" + QR.min_width + "px)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (!isFinite(video.duration)) {
|
||||||
if (!isFinite(video.duration)) {
|
QR.error("" + file.name + ": Video lacks duration metadata (try remuxing)");
|
||||||
QR.error("" + file.name + ": Video lacks duration metadata (try remuxing)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
if (duration > QR.max_duration_video) {
|
||||||
if (duration > QR.max_duration_video) {
|
QR.error("" + file.name + ": Video too long (video: " + duration + "s, max: " + QR.max_duration_video + "s)");
|
||||||
QR.error("" + file.name + ": Video too long (video: " + duration + "s, max: " + QR.max_duration_video + "s)");
|
pass = false;
|
||||||
pass = false;
|
}
|
||||||
}
|
cb(pass);
|
||||||
cb(pass);
|
return cb = null;
|
||||||
return cb = null;
|
});
|
||||||
};
|
$.on(video, 'error', function() {
|
||||||
})(this));
|
var _ref;
|
||||||
$.on(video, 'error', (function(_this) {
|
if (!cb) {
|
||||||
return function() {
|
return;
|
||||||
var _ref;
|
}
|
||||||
if (cb == null) {
|
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) >= 0) {
|
||||||
return;
|
QR.error("" + file.name + ": Video appears corrupt");
|
||||||
}
|
}
|
||||||
if (_ref = file.type, __indexOf.call(QR.mimeTypes, _ref) >= 0) {
|
cb(false);
|
||||||
QR.error("" + file.name + ": Video appears corrupt");
|
return cb = null;
|
||||||
}
|
});
|
||||||
cb(false);
|
|
||||||
return cb = null;
|
|
||||||
};
|
|
||||||
})(this));
|
|
||||||
return video.src = URL.createObjectURL(file);
|
return video.src = URL.createObjectURL(file);
|
||||||
} else {
|
} else {
|
||||||
return cb(true);
|
return cb(true);
|
||||||
|
|||||||
@ -356,8 +356,9 @@ QR =
|
|||||||
$.addClass QR.nodes.el, 'dump' unless files.length is 1
|
$.addClass QR.nodes.el, 'dump' unless files.length is 1
|
||||||
|
|
||||||
handleFile: (file, index, nfiles) ->
|
handleFile: (file, index, nfiles) ->
|
||||||
|
isSingle = nfiles is 1
|
||||||
if /^text\//.test file.type
|
if /^text\//.test file.type
|
||||||
if nfiles is 1
|
if isSingle
|
||||||
post = QR.selected
|
post = QR.selected
|
||||||
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).com
|
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).com
|
||||||
post = new QR.post()
|
post = new QR.post()
|
||||||
@ -365,14 +366,14 @@ QR =
|
|||||||
return
|
return
|
||||||
unless file.type in QR.mimeTypes
|
unless file.type in QR.mimeTypes
|
||||||
QR.error "#{file.name}: Unsupported file type."
|
QR.error "#{file.name}: Unsupported file type."
|
||||||
return unless nfiles is 1
|
return unless isSingle
|
||||||
max = QR.nodes.fileInput.max
|
max = QR.nodes.fileInput.max
|
||||||
max = Math.min(max, QR.max_size_video) if /^video\//.test file.type
|
max = Math.min(max, QR.max_size_video) if /^video\//.test file.type
|
||||||
if file.size > max
|
if file.size > max
|
||||||
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
||||||
return unless nfiles is 1
|
return unless isSingle
|
||||||
isNewPost = false
|
isNewPost = false
|
||||||
if nfiles is 1
|
if isSingle
|
||||||
post = QR.selected
|
post = QR.selected
|
||||||
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).file
|
else if index isnt 0 or (post = QR.posts[QR.posts.length - 1]).file
|
||||||
isNewPost = true
|
isNewPost = true
|
||||||
@ -382,7 +383,7 @@ QR =
|
|||||||
else
|
else
|
||||||
post.setFile file
|
post.setFile file
|
||||||
QR.checkDimensions file, (pass) ->
|
QR.checkDimensions file, (pass) ->
|
||||||
if pass or nfiles is 1
|
if pass or isSingle
|
||||||
post.setFile file
|
post.setFile file
|
||||||
else if isNewPost
|
else if isNewPost
|
||||||
post.rm()
|
post.rm()
|
||||||
@ -390,7 +391,7 @@ QR =
|
|||||||
checkDimensions: (file, cb) ->
|
checkDimensions: (file, cb) ->
|
||||||
if /^image\//.test file.type
|
if /^image\//.test file.type
|
||||||
img = new Image()
|
img = new Image()
|
||||||
img.onload = =>
|
img.onload = ->
|
||||||
{height, width} = img
|
{height, width} = img
|
||||||
pass = true
|
pass = true
|
||||||
if height > QR.max_height or width > QR.max_width
|
if height > QR.max_height or width > QR.max_width
|
||||||
@ -403,8 +404,8 @@ QR =
|
|||||||
img.src = URL.createObjectURL file
|
img.src = URL.createObjectURL file
|
||||||
else if /^video\//.test file.type
|
else if /^video\//.test file.type
|
||||||
video = $.el 'video'
|
video = $.el 'video'
|
||||||
$.on video, 'loadedmetadata', =>
|
$.on video, 'loadedmetadata', ->
|
||||||
return unless cb?
|
return unless cb
|
||||||
{videoHeight, videoWidth, duration} = video
|
{videoHeight, videoWidth, duration} = video
|
||||||
max_height = Math.min(QR.max_height, QR.max_height_video)
|
max_height = Math.min(QR.max_height, QR.max_height_video)
|
||||||
max_width = Math.min(QR.max_width, QR.max_width_video)
|
max_width = Math.min(QR.max_width, QR.max_width_video)
|
||||||
@ -428,8 +429,8 @@ QR =
|
|||||||
<% } %>
|
<% } %>
|
||||||
cb pass
|
cb pass
|
||||||
cb = null
|
cb = null
|
||||||
$.on video, 'error', =>
|
$.on video, 'error', ->
|
||||||
return unless cb?
|
return unless cb
|
||||||
if file.type in QR.mimeTypes
|
if file.type in QR.mimeTypes
|
||||||
# only report error here if we should have been able to play the video
|
# only report error here if we should have been able to play the video
|
||||||
# otherwise "unsupported type" should already have been shown
|
# otherwise "unsupported type" should already have been shown
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user