* update download file's name

* fix lint error

* use moment.js

* slugify filename

* fix lint error
This commit is contained in:
Mr.tang 2018-02-13 10:28:06 -06:00 committed by Cassie Tarakajian
parent 9f25a9ea6a
commit 6f5472020c
3 changed files with 7 additions and 1 deletions

View file

@ -167,6 +167,7 @@ class Nav extends React.PureComponent {
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={() => {
this.props.autosaveProject();
this.props.exportProjectAsZip(this.props.project.id); this.props.exportProjectAsZip(this.props.project.id);
this.setDropdown('none'); this.setDropdown('none');
}} }}
@ -487,6 +488,7 @@ class Nav extends React.PureComponent {
Nav.propTypes = { Nav.propTypes = {
newProject: PropTypes.func.isRequired, newProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired, saveProject: PropTypes.func.isRequired,
autosaveProject: PropTypes.func.isRequired,
exportProjectAsZip: PropTypes.func.isRequired, exportProjectAsZip: PropTypes.func.isRequired,
cloneProject: PropTypes.func.isRequired, cloneProject: PropTypes.func.isRequired,
user: PropTypes.shape({ user: PropTypes.shape({

View file

@ -208,6 +208,7 @@ class IDEView extends React.Component {
user={this.props.user} user={this.props.user}
newProject={this.props.newProject} newProject={this.props.newProject}
saveProject={this.props.saveProject} saveProject={this.props.saveProject}
autosaveProject={this.props.autosaveProject}
exportProjectAsZip={this.props.exportProjectAsZip} exportProjectAsZip={this.props.exportProjectAsZip}
cloneProject={this.props.cloneProject} cloneProject={this.props.cloneProject}
project={this.props.project} project={this.props.project}

View file

@ -2,6 +2,7 @@ import archiver from 'archiver';
import request from 'request'; import request from 'request';
import moment from 'moment'; import moment from 'moment';
import isUrl from 'is-url'; import isUrl from 'is-url';
import slugify from 'slugify';
import jsdom, { serializeDocument } from 'jsdom'; import jsdom, { serializeDocument } from 'jsdom';
import Project from '../models/project'; import Project from '../models/project';
import User from '../models/user'; import User from '../models/user';
@ -261,7 +262,9 @@ function buildZip(project, req, res) {
res.status(500).send({ error: err.message }); res.status(500).send({ error: err.message });
}); });
res.attachment(`${project.name}.zip`); const currentTime = moment().format('YYYY_MM_DD_HH_mm_ss');
project.slug = slugify(project.name, '_');
res.attachment(`${project.slug}_${currentTime}.zip`);
zip.pipe(res); zip.pipe(res);
function addFileToZip(file, path) { function addFileToZip(file, path) {