Handle max file size before we process with server
This commit is contained in:
parent
c38ed64308
commit
1ce5b5b34f
3 changed files with 19 additions and 1 deletions
BIN
app/soapbox/actions/__tests__/compose.test.js
Normal file
BIN
app/soapbox/actions/__tests__/compose.test.js
Normal file
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,10 @@
|
|||
export const truncateFilename = (url, maxLength) => {
|
||||
const truncateFilename = (url: string, maxLength: number) => {
|
||||
const filename = url.split('/').pop();
|
||||
|
||||
if (!filename) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
if (filename.length <= maxLength) return filename;
|
||||
|
||||
return [
|
||||
|
@ -8,3 +12,17 @@ export const truncateFilename = (url, maxLength) => {
|
|||
filename.substr(filename.length - maxLength/2),
|
||||
].join('…');
|
||||
};
|
||||
|
||||
const formatBytes = (bytes: number, decimals: number = 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 { formatBytes, truncateFilename };
|
||||
|
|
Loading…
Reference in a new issue