-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2429 - File attachment in chat should show the size #2435
Merged
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eccdb45
determine if an image needs compression or not
SebinSong 4511cef
implement compressImage() function
SebinSong 59e92d9
write a function that checks if image/webp format is supported
SebinSong 0866b47
implement recursive compression logic in compressImage()
SebinSong d4712f9
optimise compression factors / some corrections on file details post …
SebinSong 342892a
update the minimum quality
SebinSong 657ff07
fix the typo iamge
SebinSong db4564d
do not resize the image unless its physical size is too large
SebinSong 6a7cd96
attachment data in contracts needs size field
SebinSong 2f2855d
file-size to a human readable string / display it in multiple UIs
SebinSong 800f3cb
resolve merge conflicts from the master
SebinSong 73d18db
update according to feedback
SebinSong 1cb398e
update maximum image dimension
SebinSong d4eac04
remove console.log / revert back webP format as default
SebinSong 1985f28
add a constant for kilo-byte
SebinSong 2ae723d
Merge branch 'sebin/task/#2411-compress-images-before-uploading' into…
SebinSong 08b04bd
Merge remote-tracking branch 'origin/master' into sebin/task/#2429-fi…
SebinSong 333dd19
updates for PR review
SebinSong b638fce
file size update after image compression
SebinSong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,17 @@ export const getFileType = ( | |
return mimeType.match('image/') ? 'image' : 'non-image' | ||
} | ||
|
||
export const formatBytesDecimal = (bytes: number, decimals: number = 2): string => { | ||
if (bytes === 0) { return '0 Bytes' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add some other checks here: if (bytes < 0 || !Number.isFinite(bytes)) return 'Invalid size' |
||
|
||
const k = 1000 // Decimal base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be 1024, as 1024 bytes = 1KB |
||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | ||
const i = Math.floor(Math.log(bytes) / Math.log(k)) | ||
|
||
const formattedValue = parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) | ||
return `${formattedValue} ${sizes[i]}` | ||
} | ||
|
||
/** | ||
* this function filters `list` by `keyword` | ||
* `list` should be an array of objects and strings | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some observations:
arrayOf
on line 68optional
, and make this size here mandatory.CHAT_ATTACHMENT_SIZE_LIMIT
could change in the future and even be an admin configurable value, let's make this valueNumber.MAX_SAFE_INTEGER
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. updated.