mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	Created the possibility to send audio as an attachment via the dashboard. The channels that can send audio are the same channels that can send any type of attachment. Used RecordRTC (https://github.com/muaz-khan/RecordRTC) to capture the audio and Wavesurfer (https://github.com/katspaugh/wavesurfer.js) to display the audio waves. RecordRTC can be used to record videos if necessary. Fixes #1973
		
			
				
	
	
		
			26 lines
		
	
	
		
			746 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			746 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
export const formatBytes = (bytes, decimals = 2) => {
 | 
						|
  if (bytes === 0) return '0 Bytes';
 | 
						|
 | 
						|
  const k = 1024;
 | 
						|
  const dm = decimals < 0 ? 0 : decimals;
 | 
						|
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
 | 
						|
 | 
						|
  const i = Math.floor(Math.log(bytes) / Math.log(k));
 | 
						|
 | 
						|
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
 | 
						|
};
 | 
						|
 | 
						|
export const fileSizeInMegaBytes = bytes => {
 | 
						|
  if (bytes === 0) {
 | 
						|
    return 0;
 | 
						|
  }
 | 
						|
  const sizeInMB = (bytes / (1024 * 1024)).toFixed(2);
 | 
						|
  return sizeInMB;
 | 
						|
};
 | 
						|
 | 
						|
export const checkFileSizeLimit = (file, maximumUploadLimit) => {
 | 
						|
  const fileSize = file?.file?.size || file?.size;
 | 
						|
  const fileSizeInMB = fileSizeInMegaBytes(fileSize);
 | 
						|
  return fileSizeInMB <= maximumUploadLimit;
 | 
						|
};
 |