Commit 269b40de authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix jszip load history

parent 3ad44948
...@@ -254,10 +254,11 @@ function loadFileContent(url, callback) { ...@@ -254,10 +254,11 @@ function loadFileContent(url, callback) {
}); });
} }
function getJSZipUtils() { function getJSZipUtils() {
return window['JSZipUtils'] ? window['JSZipUtils'] : require('jsziputils'); return window['JSZipUtils'] ? window['JSZipUtils'] : require('jsziputils');
} }
function getImageFromChanges (name) {
function getImageFromChanges(name) {
var file; var file;
var ext = GetFileExtension(name); var ext = GetFileExtension(name);
if (null !== ext && oZipChanges && (file = oZipChanges.files[name])) { if (null !== ext && oZipChanges && (file = oZipChanges.files[name])) {
...@@ -265,10 +266,11 @@ function getImageFromChanges (name) { ...@@ -265,10 +266,11 @@ function getImageFromChanges (name) {
return 'data:image/' + ext + ';base64,' + AscCommon.Base64Encode(oFileArray, oFileArray.length, 0); return 'data:image/' + ext + ';base64,' + AscCommon.Base64Encode(oFileArray, oFileArray.length, 0);
} }
return null; return null;
} }
function openFileCommand(binUrl, changesUrl, Signature, callback) {
function openFileCommand(binUrl, changesUrl, Signature, callback) {
var bError = false, oResult = new OpenFileResult(), bEndLoadFile = false, bEndLoadChanges = false; var bError = false, oResult = new OpenFileResult(), bEndLoadFile = false, bEndLoadChanges = false;
var onEndOpen = function() { var onEndOpen = function () {
if (bEndLoadFile && bEndLoadChanges) { if (bEndLoadFile && bEndLoadChanges) {
if (callback) { if (callback) {
callback(bError, oResult); callback(bError, oResult);
...@@ -280,9 +282,7 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) { ...@@ -280,9 +282,7 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
if (!window['IS_NATIVE_EDITOR']) { if (!window['IS_NATIVE_EDITOR']) {
asc_ajax({ asc_ajax({
url: sFileUrl, url: sFileUrl, dataType: "text", success: function (result) {
dataType: "text",
success: function(result) {
//получаем url к папке с файлом //получаем url к папке с файлом
var url; var url;
var nIndex = sFileUrl.lastIndexOf("/"); var nIndex = sFileUrl.lastIndexOf("/");
...@@ -296,8 +296,7 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) { ...@@ -296,8 +296,7 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
} }
bEndLoadFile = true; bEndLoadFile = true;
onEndOpen(); onEndOpen();
}, }, error: function () {
error: function() {
bEndLoadFile = true; bEndLoadFile = true;
bError = true; bError = true;
onEndOpen(); onEndOpen();
...@@ -305,25 +304,32 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) { ...@@ -305,25 +304,32 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
}); });
} }
if (null != changesUrl) { if (changesUrl) {
getJSZipUtils().getBinaryContent(changesUrl, function(err, data) { getJSZipUtils().getBinaryContent(changesUrl, function (err, data) {
bEndLoadChanges = true;
if (err) { if (err) {
bEndLoadChanges = true;
bError = true; bError = true;
onEndOpen(); onEndOpen();
return; return;
} }
oZipChanges = new (require('jszip'))(data);
oResult.changes = []; oResult.changes = [];
for (var i in oZipChanges.files) { require('jszip').loadAsync(data).then(function (zipChanges) {
if (i.endsWith('.json')) { var promises = [];
// Заглушка на имя файла (стоило его начинать с цифры) zipChanges.forEach(function (relativePath, file) {
oResult.changes[parseInt(i.slice('changes'.length))] = JSON.parse(oZipChanges.files[i].asText()); if (relativePath.endsWith('.json')) {
promises[parseInt(relativePath.slice('changes'.length))] = file.async('string');
} }
});
Promise.all(promises).then(function (values) {
for (var i = 0; i < values.length; ++i) {
oResult.changes[i] = JSON.parse(values[i]);
} }
bEndLoadChanges = true;
onEndOpen(); onEndOpen();
}); });
});
});
} else { } else {
bEndLoadChanges = true; bEndLoadChanges = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment