-
Notifications
You must be signed in to change notification settings - Fork 0
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
Repair photos #897
Open
trollepierre
wants to merge
5
commits into
dev
Choose a base branch
from
repair-photos
base: dev
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.
+222
−62
Open
Repair photos #897
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b636a03
chore(test): mute a console error in test
trollepierre f6f60d4
chore(bsr): rename synchronize articles spec files
trollepierre f5f95db
feat(photos): allow admin to repair photos of articles
trollepierre 79776cd
feat(error): manage unhandled exception
trollepierre 619be86
feat(admin): add repair photos gallery button on admin page
trollepierre 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import flatten from 'lodash/flatten' | ||
import isEmpty from 'lodash/isEmpty' | ||
import photoRepository from '../../domain/repositories/photo-repository' | ||
import DropboxClient from '../../infrastructure/external_services/dropbox-client' | ||
|
||
const createArticleGallery = (dropboxFilesPath, dropboxId) => getPhotosOfArticle(dropboxFilesPath, dropboxId) | ||
.then(photos => flatten(photos)) | ||
.then(photos => photoRepository.createPhotos(photos)) | ||
|
||
function getPhotosOfArticle(dropboxFilesPath, dropboxId) { | ||
const paths = filterOnlyGalleryPhotos(dropboxFilesPath) | ||
return createPhotoOfArticle(paths, dropboxId) | ||
} | ||
|
||
function filterOnlyGalleryPhotos(paths) { | ||
const photosPaths = paths.filter(path => { | ||
const extension = path.split('.').pop() | ||
return extension === 'jpg' || extension === 'jpeg' || extension === 'png' | ||
}) | ||
return photosPaths.filter(path => { | ||
const shortName = path.split('/').pop().substring(0, 3) | ||
return !shortName.match('[iI]mg') | ||
}) | ||
} | ||
|
||
function createPhotoOfArticle(paths, dropboxId) { | ||
const allImgLinks = paths.reduce((promises, path) => { | ||
const imgLink = serializePhoto(path, dropboxId) | ||
promises.push(imgLink) | ||
return promises | ||
}, []) | ||
return Promise.all(allImgLinks) | ||
} | ||
|
||
function serializePhoto(path, dropboxId) { | ||
return DropboxClient.createSharedLink(path) | ||
.then(response => ({ | ||
imgLink: _transformToImgLink(response), | ||
dropboxId, | ||
})) | ||
} | ||
|
||
function _transformToImgLink(response) { | ||
if (isEmpty(response)) { | ||
console.error('is empty imgLink') | ||
return '' | ||
} | ||
const split = response.url.replace(/....$/, '').split('/s/') | ||
return `${split[0]}/s/raw/${split[1].split('?')[0]}` | ||
} | ||
|
||
export default { | ||
createArticleGallery, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import photoRepository from '../domain/repositories/photo-repository' | ||
import DropboxClient from '../infrastructure/external_services/dropbox-client' | ||
import CreateArticleGallery from './services/create-article-gallery' | ||
|
||
async function sync(dropboxId) { | ||
photoRepository.deletePhotosOfArticle(dropboxId) | ||
const dropboxFilesPath = await DropboxClient.getFilesFolderPaths(dropboxId) | ||
return CreateArticleGallery.createArticleGallery(dropboxFilesPath, dropboxId) | ||
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. need to test the returned |
||
} | ||
|
||
export default { | ||
sync, | ||
} |
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
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.
take time to work on that