when exporting to zip, also add images

This commit is contained in:
catarak 2016-07-20 15:33:37 -04:00
parent cc231cbacd
commit 2affe457d2
4 changed files with 23 additions and 8 deletions

View file

@ -64,7 +64,8 @@ export function createFile(formProps) {
dispatch({
type: ActionTypes.CREATE_FILE,
name: formProps.name,
id: `${maxFileId + 1}`
id: `${maxFileId + 1}`,
url: formProps.url
});
dispatch({
type: ActionTypes.HIDE_MODAL

View file

@ -2,8 +2,10 @@ import * as ActionTypes from '../../../constants';
import { browserHistory } from 'react-router';
import axios from 'axios';
import JSZip from 'jszip';
import JSZipUtils from 'jszip-utils';
import { saveAs } from 'file-saver';
import { getBlobUrl } from './files';
import async from 'async';
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@ -117,13 +119,23 @@ export function exportProjectAsZip() {
console.log('exporting project!');
const state = getState();
const zip = new JSZip();
state.files.forEach(file => {
zip.file(file.name, file.content);
async.each(state.files, (file, cb) => {
console.log(file);
if (file.url) {
JSZipUtils.getBinaryContent(file.url, (err, data) => {
zip.file(file.name, data, { binary: true });
cb();
});
} else {
zip.file(file.name, file.content);
cb();
}
}, err => {
if (err) console.log(err);
zip.generateAsync({ type: 'blob' }).then((content) => {
saveAs(content, `${state.project.name}.zip`);
});
});
};
}

View file

@ -72,7 +72,7 @@ const files = (state = initialState, action) => {
case ActionTypes.SET_PROJECT:
return [...action.files];
case ActionTypes.CREATE_FILE:
return [...state, { name: action.name, id: action.id, content: '' }];
return [...state, { name: action.name, id: action.id, content: '', url: action.url }];
default:
return state;
}

View file

@ -56,6 +56,7 @@
"node": ">=4"
},
"dependencies": {
"async": "^2.0.0",
"axios": "^0.12.0",
"babel-core": "^6.8.0",
"bcrypt-nodejs": "0.0.3",
@ -77,6 +78,7 @@
"htmlhint": "^0.9.13",
"jshint": "^2.9.2",
"jszip": "^3.0.0",
"jszip-utils": "0.0.2",
"moment": "^2.14.1",
"mongoose": "^4.4.16",
"node-uuid": "^1.4.7",