-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor file organization #4278
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
Open
SteRiccio
wants to merge
10
commits into
master
Choose a base branch
from
refactor/file-organization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b280c04
Refactor file organization
SteRiccio 911bea9
code cleanup
SteRiccio 684beeb
code cleanup
SteRiccio 6efa438
code cleanup
SteRiccio 1bc8ace
code cleanup
SteRiccio 9869e99
Merge branch 'master' into refactor/file-organization
mergify[bot] 02a7881
Merge branch 'master' into refactor/file-organization
mergify[bot] a991a04
Merge branch 'master' into refactor/file-organization
mergify[bot] 826075d
Merge branch 'master' into refactor/file-organization
mergify[bot] fd84432
Merge branch 'master' into refactor/file-organization
mergify[bot] 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
34 changes: 31 additions & 3 deletions
34
server/modules/record/repository/fileRepositoryS3Bucket.js
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 |
|---|---|---|
| @@ -1,9 +1,37 @@ | ||
| import { createS3BucketRepository } from '@server/modules/file/repository/fileRepositoryS3BucketCommon' | ||
| import { | ||
| checkFileExistsInS3, | ||
| copyObjectInS3, | ||
| createS3BucketRepository, | ||
| deleteObjectFromS3, | ||
| } from '@server/modules/file/repository/fileRepositoryS3BucketCommon' | ||
|
|
||
| export { checkCanAccessS3Bucket } from '@server/modules/file/repository/fileRepositoryS3BucketCommon' | ||
|
|
||
| const getFileKey = ({ surveyId, fileUuid }) => `${surveyId}_${fileUuid}` | ||
| const getSubfolder = ({ recordUuid }) => (recordUuid ? 'record_files' : 'survey_files') | ||
|
|
||
| const { uploadFileContent, getFileContentAsStream, deleteFiles } = createS3BucketRepository({ getFileKey }) | ||
| const getFileKey = ({ surveyId, fileUuid, recordUuid = null }) => | ||
| `${surveyId}/${getSubfolder({ recordUuid })}/${fileUuid}` | ||
|
|
||
| const getLegacyFileKey = ({ surveyId, fileUuid }) => `${surveyId}_${fileUuid}` | ||
|
|
||
| const { uploadFileContent, getFileContentAsStream, deleteFile } = createS3BucketRepository({ getFileKey }) | ||
|
|
||
| const deleteFiles = async ({ surveyId, files }) => { | ||
| for (const { fileUuid, recordUuid } of files) { | ||
| await deleteFile({ surveyId, fileUuid, recordUuid }) | ||
| } | ||
| } | ||
|
|
||
| export const migrateFileToNewKey = async ({ surveyId, fileUuid, recordUuid }) => { | ||
| const legacyKey = getLegacyFileKey({ surveyId, fileUuid }) | ||
| const exists = await checkFileExistsInS3({ key: legacyKey }) | ||
| if (!exists) { | ||
| return false | ||
| } | ||
| const newKey = getFileKey({ surveyId, fileUuid, recordUuid }) | ||
| await copyObjectInS3({ sourceKey: legacyKey, destinationKey: newKey }) | ||
| await deleteObjectFromS3({ key: legacyKey }) | ||
| return true | ||
| } | ||
|
|
||
| export { uploadFileContent, getFileContentAsStream, deleteFiles } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.