mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-06 01:24:52 +02:00
add correct files to zip and test zip download
This commit is contained in:
parent
eb7732ccb5
commit
cd1c82956e
@ -18,7 +18,8 @@ import {
|
||||
saveAsHtml,
|
||||
handleDownloadsPermission,
|
||||
downloadFile,
|
||||
getCompleteHtml
|
||||
getCompleteHtml,
|
||||
getFilenameFromUrl
|
||||
} from '../utils';
|
||||
import { itemService } from '../itemService';
|
||||
import '../db';
|
||||
@ -1054,7 +1055,7 @@ export default class App extends Component {
|
||||
.then(data => {
|
||||
return {
|
||||
code: data,
|
||||
url: 'dsfds'
|
||||
fileName: getFilenameFromUrl(lib)
|
||||
};
|
||||
})
|
||||
);
|
||||
@ -1080,17 +1081,17 @@ export default class App extends Component {
|
||||
zip.file('index.html', fileContent);
|
||||
for (let i = 3; i < result.length; 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;
|
||||
if (0 && JSZip.support.uint8array) {
|
||||
promise = zip.generateAsync({ type: 'uint8array' });
|
||||
} else {
|
||||
promise = zip.generateAsync({
|
||||
type: 'string',
|
||||
type: 'base64',
|
||||
compression: 'DEFLATE',
|
||||
compressionOptions: {
|
||||
level: 9
|
||||
@ -1100,10 +1101,14 @@ export default class App extends Component {
|
||||
|
||||
promise.then(data => {
|
||||
const zipContent = data;
|
||||
const size = this.calculateTextSize(data);
|
||||
const size = this.calculateTextSize(atob(data));
|
||||
this.setState({
|
||||
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({
|
||||
isJs13KModalOpen: true
|
||||
});
|
||||
document.body.appendChild(window.anchor);
|
||||
window.anchor.click();
|
||||
}
|
||||
blankTemplateSelectHandler() {
|
||||
this.createNewItem();
|
||||
|
11
src/utils.js
11
src/utils.js
@ -445,6 +445,17 @@ export function handleDownloadsPermission() {
|
||||
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) {
|
||||
document.body.classList.add('is-extension');
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user