Commit 61a298f6 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix jszip get images from changes

parent a1397636
...@@ -115,13 +115,15 @@ String.prototype.strongMatch = function(regExp){ ...@@ -115,13 +115,15 @@ String.prototype.strongMatch = function(regExp){
return false; return false;
}; };
if (typeof require =="function" && !window["XRegExp"]){window["XRegExp"] = require("xregexp");} if (typeof require === "function" && !window["XRegExp"]) {
window["XRegExp"] = require("xregexp");
}
var oZipChanges = null; var oZipImages = null;
var sDownloadServiceLocalUrl = "../../../../downloadas"; var sDownloadServiceLocalUrl = "../../../../downloadas";
var sUploadServiceLocalUrl = "../../../../upload"; var sUploadServiceLocalUrl = "../../../../upload";
var sUploadServiceLocalUrlOld = "../../../../uploadold"; var sUploadServiceLocalUrlOld = "../../../../uploadold";
var nMaxRequestLength = 5242880;//5mb <requestLimits maxAllowedContentLength="30000000" /> default 30mb var nMaxRequestLength = 5242880;//5mb <requestLimits maxAllowedContentLength="30000000" /> default 30mb
function getBaseUrl() { function getBaseUrl() {
var index_html = window["location"]["href"]; var index_html = window["location"]["href"];
...@@ -259,11 +261,10 @@ function loadFileContent(url, callback) { ...@@ -259,11 +261,10 @@ function loadFileContent(url, callback) {
} }
function getImageFromChanges(name) { function getImageFromChanges(name) {
var file; var content;
var ext = GetFileExtension(name); var ext = GetFileExtension(name);
if (null !== ext && oZipChanges && (file = oZipChanges.files[name])) { if (null !== ext && oZipImages && (content = oZipImages[name])) {
var oFileArray = file.asUint8Array(); return 'data:image/' + ext + ';base64,' + AscCommon.Base64Encode(content, content.length, 0);
return 'data:image/' + ext + ';base64,' + AscCommon.Base64Encode(oFileArray, oFileArray.length, 0);
} }
return null; return null;
} }
...@@ -305,6 +306,7 @@ function loadFileContent(url, callback) { ...@@ -305,6 +306,7 @@ function loadFileContent(url, callback) {
} }
if (changesUrl) { if (changesUrl) {
oZipImages = {};
getJSZipUtils().getBinaryContent(changesUrl, function (err, data) { getJSZipUtils().getBinaryContent(changesUrl, function (err, data) {
if (err) { if (err) {
bEndLoadChanges = true; bEndLoadChanges = true;
...@@ -315,15 +317,20 @@ function loadFileContent(url, callback) { ...@@ -315,15 +317,20 @@ function loadFileContent(url, callback) {
oResult.changes = []; oResult.changes = [];
require('jszip').loadAsync(data).then(function (zipChanges) { require('jszip').loadAsync(data).then(function (zipChanges) {
var relativePaths = [];
var promises = []; var promises = [];
zipChanges.forEach(function (relativePath, file) { zipChanges.forEach(function (relativePath, file) {
if (relativePath.endsWith('.json')) { relativePaths.push(relativePath);
promises[parseInt(relativePath.slice('changes'.length))] = file.async('string'); promises.push(file.async(relativePath.endsWith('.json') ? 'string' : 'uint8array'));
}
}); });
Promise.all(promises).then(function (values) { Promise.all(promises).then(function (values) {
var relativePath;
for (var i = 0; i < values.length; ++i) { for (var i = 0; i < values.length; ++i) {
oResult.changes[i] = JSON.parse(values[i]); if ((relativePath = relativePaths[i]).endsWith('.json')) {
oResult.changes[parseInt(relativePath.slice('changes'.length))] = JSON.parse(values[i]);
} else {
oZipImages[relativePath] = values[i];
}
} }
bEndLoadChanges = true; bEndLoadChanges = true;
onEndOpen(); onEndOpen();
...@@ -331,6 +338,7 @@ function loadFileContent(url, callback) { ...@@ -331,6 +338,7 @@ function loadFileContent(url, callback) {
}); });
}); });
} else { } else {
oZipImages = null;
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