Skip to content

Commit

Permalink
Fix #1771: Correct inadvertent revert in #1777
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed May 10, 2022
1 parent aff4b0d commit 89be70d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
61 changes: 35 additions & 26 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@
loaded: loaded,
total: total,
bps: fm.bps,
bitrate: self._getSize(fm.bps, self.bitRateUnits),
bitrate: self._getSize(fm.bps, false, self.bitRateUnits),
pendingBytes: pendingBytes
};
if (id) {
Expand Down Expand Up @@ -4175,25 +4175,35 @@
var self = this;
$h.addCss(self.$captionContainer, 'icon-visible');
},
_getSize: function (bytes, sizes) {
var self = this, size = parseFloat(bytes), i, func = self.fileSizeGetter, out;
_getSize: function (bytes, skipTemplate, sizeUnits) {
var self = this, size = parseFloat(bytes), i = 0, factor = self.bytesToKB, func = self.fileSizeGetter, out,
sizeHuman = size, newSize;
if (!$.isNumeric(bytes) || !$.isNumeric(size)) {
return '';
}
if (typeof func === 'function') {
out = func(size);
} else {
if (size === 0) {
out = '0.00 B';
} else {
if (!sizes) {
sizes = self.sizeUnits;
if (size > 0) {
if (!sizeUnits) {
sizeUnits = self.sizeUnits;
}
while (sizeHuman >= factor) {
sizeHuman /= factor;
++i;
}
i = Math.floor(Math.log(size) / Math.log(self.bytesToKB));
out = (size / Math.pow(self.bytesToKB, i)).toFixed(2) + ' ' + sizes[i];
if (!sizeUnits[i]) {
sizeHuman = size;
i = 0;
}
}
newSize = sizeHuman.toFixed(2);
if (newSize == sizeHuman) {
newSize = sizeHuman;
}
out = newSize + ' ' + sizeUnits[i];
}
return self._getLayoutTemplate('size').replace('{sizeText}', out);
return skipTemplate ? out : self._getLayoutTemplate('size').replace('{sizeText}', out);
},
_getFileType: function (ftype) {
var self = this;
Expand Down Expand Up @@ -5447,10 +5457,10 @@
return;
}
self.lock(true);
var file = files[i], id = self._getFileId(file), previewId = previewInitId + '-' + id, fSizeKB, j, msg,
fnImage = settings.image, typ, chk, typ1, typ2,
caption = self._getFileName(file, ''), fileSize = (file && file.size || 0) / self.bytesToKB,
fileExtExpr = '', previewData = $h.createObjectURL(file), fileCount = 0,
var file = files[i], id = self._getFileId(file), previewId = previewInitId + '-' + id,
fSize = (file && file.size || 0), sizeHuman = self._getSize(fSize, true), j, msg,
fnImage = settings.image, chk, typ, typ1, typ2, caption = self._getFileName(file, ''),
fileSize = fSize / self.bytesToKB, fileExtExpr = '', previewData = $h.createObjectURL(file), fileCount = 0,
strTypes = '', fileId, canLoad, fileReaderAborted = false,
func, knownTypes = 0, isImage, txtFlag, processFileLoaded = function () {
var isImageResized = !!fm.loadedImages[id], msg = msgProgress.setTokens({
Expand Down Expand Up @@ -5497,14 +5507,13 @@
if (!$h.isEmpty(fileExt)) {
fileExtExpr = new RegExp('\\.(' + fileExt.join('|') + ')$', 'i');
}
fSizeKB = fileSize.toFixed(2);
if (self.isAjaxUpload && fm.exists(fileId) || self._getFrame(previewId, true).length) {
var p2 = {id: previewId, index: i, fileId: fileId, file: file, files: files};
msg = self.msgDuplicateFile.setTokens({name: caption, size: fSizeKB});
msg = self.msgDuplicateFile.setTokens({name: caption, size: sizeHuman});
if (self.isAjaxUpload) {
self.duplicateErrors.push(msg);
self.isDuplicateError = true;
self._raise('fileduplicateerror', [file, fileId, caption, fSizeKB, previewId, i]);
self._raise('fileduplicateerror', [file, fileId, caption, sizeHuman, previewId, i]);
readFile(i + 1);
self._updateFileDetails(numFiles);
} else {
Expand All @@ -5520,17 +5529,17 @@
if (self.maxFileSize > 0 && fileSize > self.maxFileSize) {
msg = self.msgSizeTooLarge.setTokens({
'name': caption,
'size': fSizeKB,
'maxSize': self.maxFileSize
'size': sizeHuman,
'maxSize': self._getSize(self.maxFileSize * self.bytesToKB, true)
});
throwError(msg, file, previewId, i, fileId);
return;
}
if (self.minFileSize !== null && fileSize <= $h.getNum(self.minFileSize)) {
msg = self.msgSizeTooSmall.setTokens({
'name': caption,
'size': fSizeKB,
'minSize': self.minFileSize
'size': sizeHuman,
'minSize': self._getSize(self.minFileSize * self.bytesToKB, true)
});
throwError(msg, file, previewId, i, fileId);
return;
Expand Down Expand Up @@ -5558,7 +5567,7 @@
}
}
if (!self._canPreview(file)) {
canLoad = self.isAjaxUpload && self._raise('filebeforeload', [file, i, reader]);
canLoad = self._raise('filebeforeload', [file, i, reader]);
if (self.isAjaxUpload && canLoad) {
fm.add(file);
}
Expand Down Expand Up @@ -6278,8 +6287,8 @@
msgPlaceholder: 'Select {files} ...',
msgZoomModalHeading: 'Detailed Preview',
msgFileRequired: 'You must select a file to upload.',
msgSizeTooSmall: 'File "{name}" (<b>{size} KB</b>) is too small and must be larger than <b>{minSize} KB</b>.',
msgSizeTooLarge: 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>.',
msgSizeTooSmall: 'File "{name}" (<b>{size}</b>) is too small and must be larger than <b>{minSize}</b>.',
msgSizeTooLarge: 'File "{name}" (<b>{size}</b>) exceeds maximum allowed upload size of <b>{maxSize}</b>.',
msgFilesTooLess: 'You must select at least <b>{n}</b> {files} to upload.',
msgFilesTooMany: 'Number of files selected for upload <b>({n})</b> exceeds maximum allowed limit of <b>{m}</b>.',
msgTotalFilesTooMany: 'You can upload a maximum of <b>{m}</b> files (<b>{n}</b> files detected).',
Expand Down Expand Up @@ -6324,7 +6333,7 @@
msgImageResizeException: 'Error while resizing the image.<pre>{errors}</pre>',
msgAjaxError: 'Something went wrong with the {operation} operation. Please try again later!',
msgAjaxProgressError: '{operation} failed',
msgDuplicateFile: 'File "{name}" of same size "{size} KB" has already been selected earlier. Skipping duplicate selection.',
msgDuplicateFile: 'File "{name}" of same size "{size}" has already been selected earlier. Skipping duplicate selection.',
msgResumableUploadRetriesExceeded: 'Upload aborted beyond <b>{max}</b> retries for file <b>{file}</b>! Error Details: <pre>{error}</pre>',
msgPendingTime: '{time} remaining',
msgCalculatingTime: 'calculating time remaining',
Expand Down
Loading

0 comments on commit 89be70d

Please sign in to comment.