|
|
@@ -591,6 +591,32 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
return expirationDate;
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Convert Bytes to KB/MB/GB
|
|
|
+ *
|
|
|
+ * @name Helper.formatBytes
|
|
|
+ * @function
|
|
|
+ *
|
|
|
+ * @param {number} bytes
|
|
|
+ * @return {string}
|
|
|
+ */
|
|
|
+ me.formatBytes = function (bytes)
|
|
|
+ {
|
|
|
+ let result = '';
|
|
|
+ const kilobyte = 1000;
|
|
|
+ const decimalPoint = 2;
|
|
|
+ const sizes = [I18n._('B'), I18n._('KB'), I18n._('MB'), I18n._('GB')];
|
|
|
+ const index = Math.floor(Math.log(bytes) / Math.log(kilobyte));
|
|
|
+
|
|
|
+ if (bytes > 0) {
|
|
|
+ result = parseFloat((bytes / Math.pow(kilobyte, index)).toFixed(decimalPoint)) + ' ' + sizes[index];
|
|
|
+ } else {
|
|
|
+ result = `0 ${I18n._('B')}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* resets state, used for unit testing
|
|
|
*
|
|
|
@@ -3000,7 +3026,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
|
|
|
if (typeof fileName !== 'undefined') {
|
|
|
attachmentLink.attr('download', fileName);
|
|
|
- template.append(fileName);
|
|
|
+
|
|
|
+ const fileSize = me.getAttachmentSize(attachmentData);
|
|
|
+ template.append(`(${fileName}, ${fileSize})`);
|
|
|
}
|
|
|
|
|
|
// sanitize SVG preview
|
|
|
@@ -3202,6 +3230,25 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
return attachmentData.substring(5, mimeTypeEnd);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get attachment size in B/KB/MB/GB
|
|
|
+ *
|
|
|
+ * @name AttachmentViewer.getAttachmentSize
|
|
|
+ * @function
|
|
|
+ * @param {string} attachmentData - Base64 string
|
|
|
+ */
|
|
|
+ me.getAttachmentSize = function(attachmentData)
|
|
|
+ {
|
|
|
+ const base64Start = attachmentData.indexOf(',') + 1;
|
|
|
+ const rawData = attachmentData.substring(base64Start);
|
|
|
+ const decodedData = rawData.length > 0 ? atob(rawData) : '';
|
|
|
+
|
|
|
+ const buf = new Uint8Array(decodedData.length);
|
|
|
+ const bytes = new Blob([buf]).size;
|
|
|
+
|
|
|
+ return Helper.formatBytes(bytes);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* moves the attachment link to another element
|
|
|
*
|