-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix Password-protected PDF not handled correctly #42572
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
af4debc
fix Password-protected PDF not handled correctly
tienifr efde856
fix merge main
tienifr b71c857
fix native issue
tienifr b9335ed
fix merge main
tienifr 58d2aeb
fix use pdf lib
tienifr cdedb54
fix validateReceipt function
tienifr 084f895
fix lint
tienifr ab940b5
fix import issue
tienifr 7c135f3
fix package lock file
tienifr 09d50db
fix do not use react pdf in web
tienifr bd9e6c2
fix typecheck
tienifr ca0ca58
fix lint
tienifr a6b299a
Merge branch 'main' into fix/42078
tienifr 30a4a03
fix lint
tienifr ff9bcf4
fix lint
tienifr 332f8d9
fix merge main
tienifr 6a42d19
fix remove native fix
tienifr 6e44eb6
fix remove lib
tienifr 92d0704
fix lint
tienifr 6115929
fix lint
tienifr 166b3b2
fix typecheck
tienifr 41b00c9
fix lint
tienifr 7c9961b
fix merge main
tienifr 9ad3602
fix merge main
tienifr 61666db
fix comment
tienifr 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as pdfjsLib from 'pdfjs-dist'; | ||
import type {FileObject} from '@components/AttachmentModal'; | ||
|
||
const isPdfFilePasswordProtected = (file: FileObject): Promise<boolean> => | ||
new Promise((resolve) => { | ||
const reader = new FileReader(); | ||
|
||
reader.onload = (event) => { | ||
const arrayBuffer = event.target?.result; | ||
if (!arrayBuffer) { | ||
resolve(false); | ||
return; | ||
} | ||
try { | ||
const loadingTask = pdfjsLib.getDocument({data: arrayBuffer}); | ||
loadingTask.promise.then( | ||
() => { | ||
resolve(false); | ||
}, | ||
(error) => { | ||
if (error.name === 'PasswordException') { | ||
resolve(true); | ||
return; | ||
} | ||
resolve(false); | ||
}, | ||
); | ||
} catch (error) { | ||
resolve(false); | ||
} | ||
}; | ||
|
||
reader.onerror = () => { | ||
resolve(false); | ||
}; | ||
|
||
reader.readAsArrayBuffer(file as Blob); | ||
}); | ||
export default isPdfFilePasswordProtected; |
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
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.
then remove the else block