1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-09 11:14:56 +02:00

add correct files to zip and test zip download

This commit is contained in:
Kushagra Gour 2018-07-29 21:04:57 +05:30
parent eb7732ccb5
commit cd1c82956e
2 changed files with 24 additions and 6 deletions

View File

@ -18,7 +18,8 @@ import {
saveAsHtml, saveAsHtml,
handleDownloadsPermission, handleDownloadsPermission,
downloadFile, downloadFile,
getCompleteHtml getCompleteHtml,
getFilenameFromUrl
} from '../utils'; } from '../utils';
import { itemService } from '../itemService'; import { itemService } from '../itemService';
import '../db'; import '../db';
@ -1054,7 +1055,7 @@ export default class App extends Component {
.then(data => { .then(data => {
return { return {
code: data, code: data,
url: 'dsfds' fileName: getFilenameFromUrl(lib)
}; };
}) })
); );
@ -1080,17 +1081,17 @@ export default class App extends Component {
zip.file('index.html', fileContent); zip.file('index.html', fileContent);
for (let i = 3; i < result.length; i++) { for (let i = 3; i < result.length; i++) {
const externalLib = result[i]; const externalLib = result[i];
zip.file(externalLib.name, externalLib.code); zip.file(externalLib.fileName, externalLib.code);
} }
console.log('ORIGINAL', this.calculateTextSize(fileContent)); // console.log('ORIGINAL', this.calculateTextSize(fileContent));
var promise = null; var promise = null;
if (0 && JSZip.support.uint8array) { if (0 && JSZip.support.uint8array) {
promise = zip.generateAsync({ type: 'uint8array' }); promise = zip.generateAsync({ type: 'uint8array' });
} else { } else {
promise = zip.generateAsync({ promise = zip.generateAsync({
type: 'string', type: 'base64',
compression: 'DEFLATE', compression: 'DEFLATE',
compressionOptions: { compressionOptions: {
level: 9 level: 9
@ -1100,10 +1101,14 @@ export default class App extends Component {
promise.then(data => { promise.then(data => {
const zipContent = data; const zipContent = data;
const size = this.calculateTextSize(data); const size = this.calculateTextSize(atob(data));
this.setState({ this.setState({
codeSize: size codeSize: size
}); });
const a = document.createElement('a');
a.setAttribute('download', this.state.currentItem.name);
a.href = 'data:application/zip;base64,' + data;
window.anchor = a;
}); });
}); });
} }
@ -1112,6 +1117,8 @@ export default class App extends Component {
this.setState({ this.setState({
isJs13KModalOpen: true isJs13KModalOpen: true
}); });
document.body.appendChild(window.anchor);
window.anchor.click();
} }
blankTemplateSelectHandler() { blankTemplateSelectHandler() {
this.createNewItem(); this.createNewItem();

View File

@ -445,6 +445,17 @@ export function handleDownloadsPermission() {
return d.promise; return d.promise;
} }
/**
* Return the filename from a passed url.
* http://a.com/path/file.png -> file.png
*/
export function getFilenameFromUrl(url) {
if (!url) {
return '';
}
return url.match(/\/([^/]*)$/)[1];
}
if (window.IS_EXTENSION) { if (window.IS_EXTENSION) {
document.body.classList.add('is-extension'); document.body.classList.add('is-extension');
} else { } else {