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({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
name: formProps.name, name: formProps.name,
id: `${maxFileId + 1}` id: `${maxFileId + 1}`,
url: formProps.url
}); });
dispatch({ dispatch({
type: ActionTypes.HIDE_MODAL type: ActionTypes.HIDE_MODAL

View file

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

View file

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