-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(documents): prevent duplicate document uploads within an organization #140
Merged
Conversation
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
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.
PR Overview
This PR introduces duplicate document upload prevention by leveraging a SHA256 hash computed from file content to detect duplicates within an organization. Key changes include:
- Adding a new SHA256 hash utility and tests for computing file hashes.
- Implementing an early duplicate check in the use case and repository, with corresponding unit tests.
- Updating the database schema and error handling to enforce a unique document constraint per organization.
Reviewed Changes
File | Description |
---|---|
apps/papra-server/src/modules/documents/documents.services.test.ts | Added tests for SHA256 hash computation. |
apps/papra-server/src/modules/documents/documents.usecases.test.ts | Added tests for duplicate document handling and error propagation. |
apps/papra-server/src/modules/documents/documents.services.ts | Exposed the SHA256 hash function for file processing. |
apps/papra-server/src/modules/documents/documents.repository.test.ts | Updated tests to include the new hash field and duplicate handling. |
apps/papra-client/src/modules/documents/documents.composables.tsx | Updated client-side error handling for duplicate documents. |
apps/papra-server/src/modules/documents/documents.repository.ts | Integrated safe DB insertion and unique constraint error handling. |
apps/papra-server/src/modules/documents/documents.usecases.ts | Implemented early duplicate checking and file cleanup on insertion failure. |
apps/papra-server/src/modules/documents/documents.table.ts | Updated the schema with unique and indexed constraints on the document hash. |
apps/papra-server/src/modules/documents/documents.errors.ts | Added a dedicated error factory for duplicate document errors. |
apps/papra-server/src/modules/documents/documents.table.test.ts | Updated tests to include the new hash field in schema validation. |
apps/papra-server/src/modules/tags/tags.repository.test.ts | Adjusted tests to account for the new document hash field. |
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
apps/papra-server/src/modules/documents/documents.usecases.test.ts
Outdated
Show resolved
Hide resolved
Deploying papra-demo with
|
Latest commit: |
d847c69
|
Status: | ✅ Deploy successful! |
Preview URL: | https://f0c604cb.papra-demo.pages.dev |
Branch Preview URL: | https://document-hash.papra-demo.pages.dev |
Deploying papra-client with
|
Latest commit: |
d847c69
|
Status: | ✅ Deploy successful! |
Preview URL: | https://9408708f.papra.pages.dev |
Branch Preview URL: | https://document-hash.papra.pages.dev |
…t.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Deploying papra-docs with
|
Latest commit: |
d847c69
|
Status: | ✅ Deploy successful! |
Preview URL: | https://0d679d12.papra-2op.pages.dev |
Branch Preview URL: | https://document-hash.papra-2op.pages.dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #114