Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sdkjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
sdkjs
Commits
269b40de
Commit
269b40de
authored
Apr 13, 2017
by
Alexander.Trofimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix jszip load history
parent
3ad44948
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
83 deletions
+89
-83
common/editorscommon.js
common/editorscommon.js
+89
-83
No files found.
common/editorscommon.js
View file @
269b40de
...
...
@@ -254,98 +254,104 @@ function loadFileContent(url, callback) {
});
}
function
getJSZipUtils
()
{
return
window
[
'
JSZipUtils
'
]
?
window
[
'
JSZipUtils
'
]
:
require
(
'
jsziputils
'
);
}
function
getImageFromChanges
(
name
)
{
var
file
;
var
ext
=
GetFileExtension
(
name
);
if
(
null
!==
ext
&&
oZipChanges
&&
(
file
=
oZipChanges
.
files
[
name
]))
{
var
oFileArray
=
file
.
asUint8Array
();
return
'
data:image/
'
+
ext
+
'
;base64,
'
+
AscCommon
.
Base64Encode
(
oFileArray
,
oFileArray
.
length
,
0
);
function
getJSZipUtils
()
{
return
window
[
'
JSZipUtils
'
]
?
window
[
'
JSZipUtils
'
]
:
require
(
'
jsziputils
'
);
}
return
null
;
}
function
openFileCommand
(
binUrl
,
changesUrl
,
Signature
,
callback
)
{
var
bError
=
false
,
oResult
=
new
OpenFileResult
(),
bEndLoadFile
=
false
,
bEndLoadChanges
=
false
;
var
onEndOpen
=
function
()
{
if
(
bEndLoadFile
&&
bEndLoadChanges
)
{
if
(
callback
)
{
callback
(
bError
,
oResult
);
}
}
};
var
sFileUrl
=
binUrl
;
sFileUrl
=
sFileUrl
.
replace
(
/
\\
/g
,
"
/
"
);
if
(
!
window
[
'
IS_NATIVE_EDITOR
'
])
{
asc_ajax
({
url
:
sFileUrl
,
dataType
:
"
text
"
,
success
:
function
(
result
)
{
//получаем url к папке с файлом
var
url
;
var
nIndex
=
sFileUrl
.
lastIndexOf
(
"
/
"
);
url
=
(
-
1
!==
nIndex
)
?
sFileUrl
.
substring
(
0
,
nIndex
+
1
)
:
sFileUrl
;
if
(
0
<
result
.
length
)
{
oResult
.
bSerFormat
=
Signature
===
result
.
substring
(
0
,
Signature
.
length
);
oResult
.
data
=
result
;
oResult
.
url
=
url
;
}
else
{
bError
=
true
;
}
bEndLoadFile
=
true
;
onEndOpen
();
},
error
:
function
()
{
bEndLoadFile
=
true
;
bError
=
true
;
onEndOpen
();
}
});
}
if
(
null
!=
changesUrl
)
{
getJSZipUtils
().
getBinaryContent
(
changesUrl
,
function
(
err
,
data
)
{
bEndLoadChanges
=
true
;
if
(
err
)
{
bError
=
true
;
onEndOpen
();
return
;
}
function
getImageFromChanges
(
name
)
{
var
file
;
var
ext
=
GetFileExtension
(
name
);
if
(
null
!==
ext
&&
oZipChanges
&&
(
file
=
oZipChanges
.
files
[
name
]))
{
var
oFileArray
=
file
.
asUint8Array
();
return
'
data:image/
'
+
ext
+
'
;base64,
'
+
AscCommon
.
Base64Encode
(
oFileArray
,
oFileArray
.
length
,
0
);
}
return
null
;
}
oZipChanges
=
new
(
require
(
'
jszip
'
))(
data
);
oResult
.
changes
=
[];
for
(
var
i
in
oZipChanges
.
files
)
{
if
(
i
.
endsWith
(
'
.json
'
))
{
// Заглушка на имя файла (стоило его начинать с цифры)
oResult
.
changes
[
parseInt
(
i
.
slice
(
'
changes
'
.
length
))]
=
JSON
.
parse
(
oZipChanges
.
files
[
i
].
asText
());
}
}
onEndOpen
();
});
}
else
{
bEndLoadChanges
=
true
;
}
function
openFileCommand
(
binUrl
,
changesUrl
,
Signature
,
callback
)
{
var
bError
=
false
,
oResult
=
new
OpenFileResult
(),
bEndLoadFile
=
false
,
bEndLoadChanges
=
false
;
var
onEndOpen
=
function
()
{
if
(
bEndLoadFile
&&
bEndLoadChanges
)
{
if
(
callback
)
{
callback
(
bError
,
oResult
);
}
}
};
var
sFileUrl
=
binUrl
;
sFileUrl
=
sFileUrl
.
replace
(
/
\\
/g
,
"
/
"
);
if
(
!
window
[
'
IS_NATIVE_EDITOR
'
])
{
asc_ajax
({
url
:
sFileUrl
,
dataType
:
"
text
"
,
success
:
function
(
result
)
{
//получаем url к папке с файлом
var
url
;
var
nIndex
=
sFileUrl
.
lastIndexOf
(
"
/
"
);
url
=
(
-
1
!==
nIndex
)
?
sFileUrl
.
substring
(
0
,
nIndex
+
1
)
:
sFileUrl
;
if
(
0
<
result
.
length
)
{
oResult
.
bSerFormat
=
Signature
===
result
.
substring
(
0
,
Signature
.
length
);
oResult
.
data
=
result
;
oResult
.
url
=
url
;
}
else
{
bError
=
true
;
}
bEndLoadFile
=
true
;
onEndOpen
();
},
error
:
function
()
{
bEndLoadFile
=
true
;
bError
=
true
;
onEndOpen
();
}
});
}
if
(
window
[
'
IS_NATIVE_EDITOR
'
])
{
var
result
=
window
[
"
native
"
][
"
openFileCommand
"
](
sFileUrl
,
changesUrl
,
Signature
);
if
(
changesUrl
)
{
getJSZipUtils
().
getBinaryContent
(
changesUrl
,
function
(
err
,
data
)
{
if
(
err
)
{
bEndLoadChanges
=
true
;
bError
=
true
;
onEndOpen
();
return
;
}
var
url
;
var
nIndex
=
sFileUrl
.
lastIndexOf
(
"
/
"
);
url
=
(
-
1
!==
nIndex
)
?
sFileUrl
.
substring
(
0
,
nIndex
+
1
)
:
sFileUrl
;
if
(
0
<
result
.
length
)
{
oResult
.
bSerFormat
=
Signature
===
result
.
substring
(
0
,
Signature
.
length
);
oResult
.
data
=
result
;
oResult
.
url
=
url
;
oResult
.
changes
=
[];
require
(
'
jszip
'
).
loadAsync
(
data
).
then
(
function
(
zipChanges
)
{
var
promises
=
[];
zipChanges
.
forEach
(
function
(
relativePath
,
file
)
{
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
();
});
});
});
}
else
{
bE
rror
=
true
;
bE
ndLoadChanges
=
true
;
}
bEndLoadFile
=
true
;
onEndOpen
();
if
(
window
[
'
IS_NATIVE_EDITOR
'
])
{
var
result
=
window
[
"
native
"
][
"
openFileCommand
"
](
sFileUrl
,
changesUrl
,
Signature
);
var
url
;
var
nIndex
=
sFileUrl
.
lastIndexOf
(
"
/
"
);
url
=
(
-
1
!==
nIndex
)
?
sFileUrl
.
substring
(
0
,
nIndex
+
1
)
:
sFileUrl
;
if
(
0
<
result
.
length
)
{
oResult
.
bSerFormat
=
Signature
===
result
.
substring
(
0
,
Signature
.
length
);
oResult
.
data
=
result
;
oResult
.
url
=
url
;
}
else
{
bError
=
true
;
}
bEndLoadFile
=
true
;
onEndOpen
();
}
}
}
function
sendCommand
(
editor
,
fCallback
,
rdata
,
dataContainer
)
{
//json не должен превышать размера 2097152, иначе при его чтении будет exception
var
docConnectionId
=
editor
.
CoAuthoringApi
.
getDocId
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment