Commit b67e646a authored by Boris Kocherov's avatar Boris Kocherov

use jio storrage for save document images

disable "image upload blocking" on image jio save (probably it wrong)
use modified jio_putAttachment to save image:
* if attachId undefined then attachId = mimeType,sha1hashOfFile
* not save in jio storage if attach with checksumm already exist
* return attachId
* allow dataUri instead blob
use modified jio_getAttachment allow get attachment as dataUrl or
blobUrl (ooffice use blobUrl)
disable load images as background
parent b603ac29
/* /*
* (c) Copyright Ascensio System SIA 2010-2017 * (c) Copyright Ascensio System SIA 2010-2017
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
...@@ -2339,49 +2339,31 @@ var editor; ...@@ -2339,49 +2339,31 @@ var editor;
return ret; return ret;
}; };
spreadsheet_api.prototype.asc_addImageDrawingObject = function (imageUrl) { spreadsheet_api.prototype.asc_addImageDrawingObject = function(imageUrl, callback) {
var rData = {
"id": this.documentId,
"userid": this.documentUserId,
"c": "imgurl",
"saveindex": g_oDocumentUrls.getMaxIndex(),
"data": imageUrl
};
var t = this; var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); if (!callback) {
this.fCurCallback = function (input) { callback = function (url) {
if (null != input && "imgurl" == input["type"]) { //g_oDocumentUrls.addUrls(urls);
if ("ok" == input["status"]) { var ws = t.wb.getWorksheet();
var data = input["data"]; ws.objectRender.addImageDrawingObject(['jio:' + url], null);
var urls = {}; };
var firstUrl; }
for (var i = 0; i < data.length; ++i) { //this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
var elem = data[i]; return new RSVP.Queue()
if (elem.url) { .push(function () {
if (!firstUrl) { return imageUrl;
firstUrl = elem.url; })
} .push(AscCommon.downloadUrlAsBlob)
urls[elem.path] = elem.url; .push(function (blob) {
} return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
} })
g_oDocumentUrls.addUrls(urls); .push(callback)
if (firstUrl) { //.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
var ws = t.wb.getWorksheet(); .push(undefined, function (error) {
ws.objectRender.addImageDrawingObject([firstUrl], null); console.log(error);
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])),
c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical); t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
} //t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); });
};
sendCommand(this, null, rData);
}; };
...@@ -2645,46 +2627,10 @@ var editor; ...@@ -2645,46 +2627,10 @@ var editor;
return; return;
} }
var rData = { this.asc_addImageDrawingObject(sImageUrl, function (url) {
"id": this.documentId, fReplaceCallback('jio:' + url);
"userid": this.documentUserId, ws.objectRender.setGraphicObjectProps(props);
"c": "imgurl", });
"saveindex": g_oDocumentUrls.getMaxIndex(),
"data": sImageUrl};
var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input) {
if (null != input && "imgurl" == input["type"]) {
if ("ok" == input["status"]) {
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i) {
var elem = data[i];
if (elem.url) {
if (!firstUrl) {
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl) {
fReplaceCallback(firstUrl);
ws.objectRender.setGraphicObjectProps(props);
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
} }
else{ else{
ws.objectRender.setGraphicObjectProps(props); ws.objectRender.setGraphicObjectProps(props);
......
This diff is collapsed.
...@@ -106,18 +106,24 @@ prot.addUrls = function(urls){ ...@@ -106,18 +106,24 @@ prot.addUrls = function(urls){
}; };
prot.addImageUrl = function(strPath, url){ prot.addImageUrl = function(strPath, url){
}; };
prot.getImageUrl = function(strPath){ prot.getImageUrl = function(url){
if (0 === strPath.indexOf('theme')) var _first = "jio:";
if (0 === url.indexOf(_first))
return url;
if (0 === url.indexOf('theme'))
return null; return null;
if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl != "" && strPath.indexOf(window.editor.ThemeLoader.ThemesUrl) == 0) if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl !== "" && url.indexOf(window.editor.ThemeLoader.ThemesUrl) === 0)
return null; return null;
return this.documentUrl + "/media/" + strPath; return _first + url;
//return this.documentUrl + "/media/" + strPath;
}; };
prot.getImageLocal = function(url){ prot.getImageLocal = function(url){
var _first = this.documentUrl + "/media/"; //var _first = this.documentUrl + "/media/";
if (0 == url.indexOf(_first)) var _first = "jio:";
if (0 === url.indexOf(_first))
return url.substring(_first.length); return url.substring(_first.length);
if (window.editor && window.editor.ThemeLoader && 0 == url.indexOf(editor.ThemeLoader.ThemesUrlAbs)) { if (window.editor && window.editor.ThemeLoader && 0 == url.indexOf(editor.ThemeLoader.ThemesUrlAbs)) {
......
...@@ -891,7 +891,6 @@ ...@@ -891,7 +891,6 @@
} }
else else
{ {
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), function(error, urls) AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), function(error, urls)
{ {
if (c_oAscError.ID.No !== error) if (c_oAscError.ID.No !== error)
...@@ -902,7 +901,6 @@ ...@@ -902,7 +901,6 @@
{ {
t._addImageUrl(urls); t._addImageUrl(urls);
} }
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
}); });
} }
}; };
......
...@@ -1322,61 +1322,17 @@ ...@@ -1322,61 +1322,17 @@
{ {
if (files.length > 0) if (files.length > 0)
{ {
var url = sUploadServiceLocalUrl + '/' + documentId + '/' + documentUserId + '/' + g_oDocumentUrls.getMaxIndex(); var file = files[0];
if (jwt) Common.Gateway.jio_putAttachment(documentId, undefined, file)
{ .push(function (image_url)
url += '/' + jwt; {
} callback(Asc.c_oAscError.ID.No, ['jio:' + image_url]);
})
var aFiles = []; .push(undefined, function (error)
for(var i = files.length - 1; i > - 1; --i){ {
aFiles.push(files[i]); console.log(error);
} callback(Asc.c_oAscError.ID.UplImageFileCount);
var file = aFiles.pop(); });
var aResultUrls = [];
var fOnReadyChnageState = function(){
if (4 == this.readyState){
if ((this.status == 200 || this.status == 1223)){
var urls = JSON.parse(this.responseText);
g_oDocumentUrls.addUrls(urls);
for (var i in urls)
{
if (urls.hasOwnProperty(i))
{
aResultUrls.push(urls[i]);
break;
}
}
if(aFiles.length === 0){
callback(Asc.c_oAscError.ID.No, aResultUrls);
}
else{
file = aFiles.pop();
var xhr = new XMLHttpRequest();
url = sUploadServiceLocalUrl + '/' + documentId + '/' + documentUserId + '/' + g_oDocumentUrls.getMaxIndex();
if (jwt)
{
url += '/' + jwt;
}
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
xhr.onreadystatechange = fOnReadyChnageState;
xhr.send(file);
}
}
else
callback(Asc.c_oAscError.ID.UplImageFileCount);
}
};
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
xhr.onreadystatechange = fOnReadyChnageState;
xhr.send(file);
} }
else else
{ {
......
...@@ -2746,58 +2746,11 @@ background-repeat: no-repeat;\ ...@@ -2746,58 +2746,11 @@ background-repeat: no-repeat;\
return; return;
} }
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); this.AddImageUrl(sImageUrl, function (url) {
this.fCurCallback = function(input) //g_oDocumentUrls.addUrls(urls);
{ image_url = 'jio:' + url;
if (null != input && "imgurl" == input["type"]) fApplyCallback();
{ });
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
image_url = firstUrl;
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : sImageUrl
};
sendCommand(this, null, rData);
} }
} }
else else
...@@ -3764,7 +3717,7 @@ background-repeat: no-repeat;\ ...@@ -3764,7 +3717,7 @@ background-repeat: no-repeat;\
} }
} }
}; };
asc_docs_api.prototype.AddImageUrl = function(url) asc_docs_api.prototype.AddImageUrl = function(url, callback)
{ {
if (g_oDocumentUrls.getLocal(url)) if (g_oDocumentUrls.getLocal(url))
{ {
...@@ -3772,59 +3725,32 @@ background-repeat: no-repeat;\ ...@@ -3772,59 +3725,32 @@ background-repeat: no-repeat;\
} }
else else
{ {
var rData = { var t = this,
"id" : this.documentId, start = url.slice(0, 6),
"userid" : this.documentUserId, queue = new RSVP.Queue();
"c" : "imgurl", if (!callback) {
"saveindex" : g_oDocumentUrls.getMaxIndex(), callback = function (url) {
"data" : url //g_oDocumentUrls.addUrls(urls);
}; t.AddImageUrlAction('jio:' + url);
};
var t = this; }
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); queue.push(function () {
this.fCurCallback = function(input) return url;
{ });
if (null != input && "imgurl" == input["type"]) //this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
{ if (0 !== start.indexOf('data:')) {
if ("ok" == input["status"]) queue.push(AscCommon.downloadUrlAsBlob)
{ }
var data = input["data"]; return queue.push(function (blob) {
var urls = {}; return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
var firstUrl; })
for (var i = 0; i < data.length; ++i) .push(callback)
{ //.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
var elem = data[i]; .push(undefined, function (error) {
if (elem.url) console.log(error);
{ t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
if (!firstUrl) //t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
{ });
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
t.AddImageUrlAction(firstUrl);
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
} }
}; };
...@@ -3997,70 +3923,11 @@ background-repeat: no-repeat;\ ...@@ -3997,70 +3923,11 @@ background-repeat: no-repeat;\
} }
else else
{ {
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); this.AddImageUrl(sImageUrl, function (url) {
//g_oDocumentUrls.addUrls(urls);
if (window["AscDesktopEditor"]) ImagePr.ImageUrl = 'jio:' + url;
{ fApplyCallback();
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](sImageUrl); });
_url = g_oDocumentUrls.getImageUrl(_url);
ImagePr.ImageUrl = _url;
fApplyCallback();
this.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
return;
}
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
ImagePr.ImageUrl = firstUrl;
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : sImageUrl
};
sendCommand(this, null, rData);
} }
} }
else else
......
/* /*
* (c) Copyright Ascensio System SIA 2010-2017 * (c) Copyright Ascensio System SIA 2010-2017
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
...@@ -4540,7 +4540,7 @@ background-repeat: no-repeat;\ ...@@ -4540,7 +4540,7 @@ background-repeat: no-repeat;\
} }
} }
}; };
asc_docs_api.prototype.AddImageUrl = function(url, imgProp) asc_docs_api.prototype.AddImageUrl = function(url, imgProp, callback)
{ {
if (g_oDocumentUrls.getLocal(url)) if (g_oDocumentUrls.getLocal(url))
{ {
...@@ -4548,59 +4548,29 @@ background-repeat: no-repeat;\ ...@@ -4548,59 +4548,29 @@ background-repeat: no-repeat;\
} }
else else
{ {
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : url
};
var t = this; var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage); if (!callback) {
this.fCurCallback = function(input) callback = function (url) {
{ //g_oDocumentUrls.addUrls(urls);
if (null != input && "imgurl" == input["type"]) t.AddImageUrlAction('jio:' + url, imgProp);
{ };
if ("ok" == input["status"]) }
{ //this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
var data = input["data"]; return new RSVP.Queue()
var urls = {}; .push(function () {
var firstUrl; return url;
for (var i = 0; i < data.length; ++i) })
{ .push(AscCommon.downloadUrlAsBlob)
var elem = data[i]; .push(function (blob) {
if (elem.url) return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
{ })
if (!firstUrl) .push(callback)
{ //.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
firstUrl = elem.url; .push(undefined, function (error) {
} console.log(error);
urls[elem.path] = elem.url; t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
} //t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
} });
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
t.AddImageUrlAction(firstUrl, imgProp);
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
} }
}; };
asc_docs_api.prototype.AddImageUrlAction = function(url, imgProp) asc_docs_api.prototype.AddImageUrlAction = function(url, imgProp)
...@@ -4919,59 +4889,11 @@ background-repeat: no-repeat;\ ...@@ -4919,59 +4889,11 @@ background-repeat: no-repeat;\
return; return;
} }
var rData = { this.AddImageUrl(sImageToDownLoad, undefined, function (url) {
"id" : this.documentId, //g_oDocumentUrls.addUrls(urls);
"userid" : this.documentUserId, fReplaceCallback('jio:' + url);
"c" : "imgurl", fApplyCallback();
"saveindex" : g_oDocumentUrls.getMaxIndex(), });
"data" : sImageToDownLoad
};
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
fReplaceCallback(firstUrl);
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
} }
else else
{ {
......
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