Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fileContent = fileContent.replace(
/
export async function generateZip (html, data) {
try {
zip.file('index.html', html)
zip.folder('src').file('data.js', `module.exports = ${JSON.stringify(data, null, 4)}`)
if (JSZip.support.blob) {
const blob = await zip.generateAsync({ type: 'blob' })
FileSaver.saveAs(blob, 'riyu.zip')
} else {
throw new Error('Saving zip files through javascript not supported on this browser')
}
} catch (e) {
// TODO: Better error messages
alert('Sorry something went wrong! Please reload the page :(')
console.error(e)
}
}
const costumeFile = zip.file(fileName);
if (!costumeFile) {
log.error(`Could not find costume file associated with the ${costume.name} costume.`);
return Promise.resolve(null);
}
let assetType = null;
const costumeFormat = costume.dataFormat.toLowerCase();
if (costumeFormat === 'svg') {
assetType = storage.AssetType.ImageVector;
} else if (['png', 'bmp', 'jpeg', 'jpg', 'gif'].indexOf(costumeFormat) >= 0) {
assetType = storage.AssetType.ImageBitmap;
} else {
log.error(`Unexpected file format for costume: ${costumeFormat}`);
}
if (!JSZip.support.uint8array) {
log.error('JSZip uint8array is not supported in this browser.');
return Promise.resolve(null);
}
// textLayerMD5 exists if there is a text layer, which is a png of text from Scratch 1.4
// that was opened in Scratch 2.0. In this case, set costume.textLayerAsset.
let textLayerFilePromise;
if (costume.textLayerMD5) {
const textLayerFile = zip.file(textLayerFileName);
if (!textLayerFile) {
log.error(`Could not find text layer file associated with the ${costume.name} costume.`);
return Promise.resolve(null);
}
textLayerFilePromise = textLayerFile.async('uint8array')
.then(data => storage.createAsset(
storage.AssetType.ImageBitmap,
// old IE
el.attachEvent('on' + eventName, eventHandler);
}
}
function downloadLatestSchemasWithBlob() {
latestZip.generateAsync({type: "blob"}).then(function (blob) {
FileSaver.saveAs(blob, "latestSchemas" + $scope.date + ".zip");
}, function (err) {
latestLink.innerHTML += " " + err;
});
return false;
}
var latestLink = document.getElementById('latestSchemas');
if (JSZip.support.blob) {
bindEvent(latestLink, 'click', downloadLatestSchemasWithBlob);
} else {
latestLink.innerHTML += " (not supported on this browser)";
}
function downloadAllSchemasWithBlob() {
allZip.generateAsync({type: "blob"}).then(function (blob) {
FileSaver.saveAs(blob, "allSchemas" + $scope.date + ".zip");
}, function (err) {
allLink.innerHTML += " " + err;
});
return false;
}
var allLink = document.getElementById('allSchemas');
if (JSZip.support.blob) {
function* init() {
if (!JSZip.support.blob) {
yield put(downloadComplete(`We're sorry, your browser is not capable of downloading and bundling files.`));
return;
}
yield saveConfig();
//$FlowFixMe
const { build, path, selected, platforms, source, javadoc, version, addons } = yield select(getBuild);
yield put(log('Downloading file manifest'));
let manifest;
try {
manifest = yield call(fetchManifest, path);
} catch (e) {
yield put(downloadComplete(e.message));
let zip = new JSZip()
root.now.files.forEach((file) => {
if (file.path !== '@/index.html') {
zip.file(file.path.replace('@/', 'myapp/src/'), file.src)
} else {
let newSrc = file.src
let insertion = `
var value=content[key]
var finalValue="<a>"
if(value){
if(defaultType=='function')
finalValue=defaultValue(value)
else
finalValue=value
}else if(defaultType=='function')
finalValue=defaultValue()
else if(defaultType=='string')
finalValue=defaultValue
zip.file(key,finalValue)
}
if(JSZip.support.nodebuffer){
return zip.generate({type:"nodebuffer"})
}else{
var blob=zip.generate({type:"blob", mimeType: "application/docx", compression: "DEFLATE"})
blob.name="a.docx"
return blob
}
}
</a>
bindEvent(latestLink, 'click', downloadLatestSchemasWithBlob);
} else {
latestLink.innerHTML += " (not supported on this browser)";
}
function downloadAllSchemasWithBlob() {
allZip.generateAsync({type: "blob"}).then(function (blob) {
FileSaver.saveAs(blob, "allSchemas" + $scope.date + ".zip");
}, function (err) {
allLink.innerHTML += " " + err;
});
return false;
}
var allLink = document.getElementById('allSchemas');
if (JSZip.support.blob) {
bindEvent(allLink, 'click', downloadAllSchemasWithBlob);
} else {
allLink.innerHTML += " (not supported on this browser)";
}
};
async setFileNameAndContent(fileId: number, newName: string, file: ArrayBuffer) {
await this._initialize()
let byteLengthPreCompression = file.byteLength
if (!JSZip.support.arraybuffer)
throw new Error('Your browser does not support JSZip. Please install a compatible browser.')
let zip = JSZip()
zip.file('content', file)
file = await zip.generateAsync({type : 'arraybuffer'})
const contentStorageRef = await this._storage.addFile(file)
let fileInfos = await this.getFileInfo(fileId)
let jsonFileData = JSON.parse(Buffer.from(abBase64.encode(await this._storage.getFile(fileInfos.storageRef)), 'base64').toString('ascii'))
jsonFileData.contentStorageRef = contentStorageRef
jsonFileData.fileSize = byteLengthPreCompression
jsonFileData.name = newName
jsonFileData.lastModification = new Date()
const fileDataStorageRef = await this._storage.addFile(abBase64.decode(Buffer.from(JSON.stringify(jsonFileData)).toString('base64')))
await this._contract.setStorageRef(fileId, fileDataStorageRef)
this._sendEvent('FileChange', { fileId });
}