Repository navigation
Use the original file name when downloading chat videos #104072
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
96b87e4
Use the video inner text as the download file name when data-name is …
MelvinBot 512a9bb
Replace the video attachment instead of mutating its read-only file name
MelvinBot 0d7b341
Merge remote-tracking branch 'origin/main' into claude-videoDownloadF…
MelvinBot 15658b7
Merge remote-tracking branch 'origin/main' into claude-videoDownloadF…
MelvinBot 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import extractAttachments from '@components/Attachments/AttachmentCarousel/extractAttachments'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| const ACCOUNT_ID = 1; | ||
| const VIDEO_SOURCE = 'https://www.expensify.com/chat-attachments/123/w_abc123'; | ||
|
|
||
| function extractNoteAttachments(note: string) { | ||
| return extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, { | ||
| privateNotes: {[ACCOUNT_ID]: {note}}, | ||
| accountID: ACCOUNT_ID, | ||
| report: undefined, | ||
| isReportArchived: false, | ||
| }); | ||
| } | ||
|
|
||
| describe('extractAttachments', () => { | ||
| it('uses data-name as the video file name when it is present', () => { | ||
| // Given a video tag with a data-name attribute and a different inner text | ||
| const note = `<video data-expensify-source="${VIDEO_SOURCE}" data-name="original.mp4">other.mp4</video>`; | ||
|
|
||
| // When the attachments are extracted | ||
| const attachments = extractNoteAttachments(note); | ||
|
|
||
| // Then the stored data-name is preferred | ||
| expect(attachments.at(0)?.file?.name).toBe('original.mp4'); | ||
| }); | ||
|
|
||
| it('uses the inner text as the video file name when data-name is missing', () => { | ||
| // Given a server-rendered video tag that carries the original file name only as its inner text | ||
| const note = `<video data-expensify-source="${VIDEO_SOURCE}">clip.mp4</video>`; | ||
|
|
||
| // When the attachments are extracted | ||
| const attachments = extractNoteAttachments(note); | ||
|
|
||
| // Then the original file name is used instead of the storage key from the URL | ||
| expect(attachments.at(0)?.file?.name).toBe('clip.mp4'); | ||
| }); | ||
|
|
||
| it('falls back to the URL file name when data-name and inner text are missing', () => { | ||
| // Given a video tag with neither data-name nor inner text | ||
| const note = `<video data-expensify-source="${VIDEO_SOURCE}"></video>`; | ||
|
|
||
| // When the attachments are extracted | ||
| const attachments = extractNoteAttachments(note); | ||
|
|
||
| // Then the last part of the source URL is used, since there is no other name to use | ||
| expect(attachments.at(0)?.file?.name).toBe('w_abc123'); | ||
| }); | ||
|
|
||
| it('does not use text that follows a video as its file name', () => { | ||
| // Given an empty video tag followed by regular comment text | ||
| const note = `<video data-expensify-source="${VIDEO_SOURCE}"></video>Some comment`; | ||
|
|
||
| // When the attachments are extracted | ||
| const attachments = extractNoteAttachments(note); | ||
|
|
||
| // Then the text outside the video tag is ignored | ||
| expect(attachments.at(0)?.file?.name).toBe('w_abc123'); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
When a legacy video filename contains an encoded character, such as
<video ...>clip&demo.mp4</video>, htmlparser2 may invokeontextmultiple times for that single text node; its documentation explicitly says consumers may need to stitch the pieces together (htmlparser2 usage). ClearingvideoAwaitingFileNameafter the first nonempty callback therefore records onlyclip, losing both the rest of the name and its extension. Accumulate the callbacks and assign the filename when</video>is reached instead.Useful? React with 👍 / 👎.