Skip to content

Commit

Permalink
removing spawm
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianovide committed Nov 13, 2018
1 parent de1812c commit 7ac53bd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 48 deletions.
15 changes: 12 additions & 3 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const functions = require('firebase-functions');
const mkdirp = require('mkdirp-promise');
const admin = require('firebase-admin');
admin.initializeApp();
const spawn = require('child-process-promise').spawn;
admin.firestore().settings({ timestampsInSnapshots: true });
const path = require('path');
const os = require('os');
const fs = require('fs');
const gm = require('gm').subClass({imageMagick: true});

const THUMB_MAX_SIZE = 50;
const THUMB_NAME = 'thumbnail.jpg';
Expand Down Expand Up @@ -62,9 +63,9 @@ exports.generateThumbnail = functions.storage.object().onFinalize(async (object)
await file.download({destination: tempLocalFile});
console.log('The file has been downloaded to', tempLocalFile);
// Generate a thumbnail using ImageMagick.
await spawn('convert', [tempLocalFile, '-thumbnail', `${THUMB_MAX_SIZE}x${THUMB_MAX_SIZE}>`, tempLocalThumbFile], {capture: ['stdout', 'stderr']});
await resize(tempLocalFile, tempLocalThumbFile, THUMB_MAX_SIZE);
console.log('Thumbnail created at', tempLocalThumbFile);
await spawn('convert', [tempLocalFile, '-thumbnail', `${MAIN_MAX_SIZE}x${MAIN_MAX_SIZE}>`, tempLocalMainFile], {capture: ['stdout', 'stderr']});
await resize(tempLocalFile, tempLocalMainFile, MAIN_MAX_SIZE);
console.log('Main created at', tempLocalMainFile);

// Uploading the Thumbnail.
Expand Down Expand Up @@ -98,3 +99,11 @@ exports.generateThumbnail = functions.storage.object().onFinalize(async (object)

return console.log(`Thumbnail URLs saved to database.`);
});

async function resize(inFile, outFile, maxSize) {
return new Promise( (resolve, reject) => {
gm(inFile).resize(maxSize,maxSize).write(outFile, (err) => {
if (err) reject(err); else resolve();
});
});
}
76 changes: 45 additions & 31 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"logs": "firebase functions:log"
},
"dependencies": {
"child-process-promise": "^2.2.0",
"mkdirp": "^0.5.1",
"mkdirp-promise": "^4.0.0",
"firebase-admin": "~6.1.0",
"firebase-functions": "^2.1.0"
"firebase-functions": "^2.1.0",
"gm": "^1.23.1",
"mkdirp": "^0.5.1",
"mkdirp-promise": "^4.0.0"
},
"devDependencies": {
"eslint": "^4.12.0",
Expand Down
12 changes: 2 additions & 10 deletions src/components/ModeratorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class ModeratorPage extends Component {
confirmDialogContent: "",
confirmDialogHandleCancel: this.handleCancelDialog,
confirmDialogHandleOk: null,
confirmDialogOpen: false,
photoDetailsOpen: false,
photoDetailsId: null
confirmDialogOpen: false
};
}

Expand Down Expand Up @@ -74,10 +72,6 @@ class ModeratorPage extends Component {
this.setState({confirmDialogOpen: false})
};

handleListItemClick = (photoDetailsId) => () => {
this.setState({photoDetailsOpen: true, photoDetailsId});
};

render() {
return (
<div className='geovation-moderatorPage'>
Expand All @@ -94,7 +88,7 @@ class ModeratorPage extends Component {
</AppBar>
<List dense={false}>
{this.props.photos.map(photo => (
<ListItem key={photo.id} button onClick={() => alert(photo)}>
<ListItem key={photo.id} button>
<Avatar alt={photo.description} src={photo.thumbnail} />
<ListItemText primary={`${photo.description}`} />
<ListItemSecondaryAction>
Expand All @@ -108,8 +102,6 @@ class ModeratorPage extends Component {
</ListItem>
))}
</List>
<PhotoDetails open={this.state.photoDetailsOpen}
photoId={this.state.photoDetailsId}/>
<Dialog open={this.state.confirmDialogOpen}>
<DialogTitle>{this.state.confirmDialogTitle}</DialogTitle>
<DialogContent>{this.state.confirmDialogContent}</DialogContent>
Expand Down

0 comments on commit 7ac53bd

Please sign in to comment.