复制外链图片, 复制到leanote

This commit is contained in:
lealife committed 2015-10-10 16:18:26 +08:00
1 parent 320263eefa
commit c844c8b188
6 files changed
+26 -64

No files matched your search

+16 -12
View File
@@ -234,35 +234,39 @@ func (c File) CopyImage(userId, fileId, toUserId string) revel.Result {
return c.RenderJson(re)
}
// 复制外网的图片, 成公共图片 放在/upload下
// 复制外网的图片
// 都要好好的计算大小
func (c File) CopyHttpImage(src string) revel.Result {
re := info.NewRe()
fileUrlPath := "upload/" + c.GetUserId() + "/images"
dir := revel.BasePath + "/public/" + fileUrlPath
// 生成上传路径
newGuid := NewGuid()
userId := c.GetUserId()
fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images"
dir := revel.BasePath + "/" + fileUrlPath
err := os.MkdirAll(dir, 0755)
if err != nil {
return c.RenderJson(re)
}
filesize, filename, _, ok := netutil.WriteUrl(src, dir)
if !ok {
re.Msg = "copy error"
return c.RenderJson(re)
}
// File
fileInfo := info.File{Name: filename,
Title: filename,
Path: fileUrlPath + "/" + filename,
Size: filesize}
id := bson.NewObjectId();
Path: fileUrlPath + "/" + filename,
Size: filesize}
id := bson.NewObjectId()
fileInfo.FileId = id
re.Id = id.Hex()
re.Item = fileInfo.Path
// re.Item = fileInfo.Path
re.Ok, re.Msg = fileService.AddImage(fileInfo, "", c.GetUserId(), true)
return c.RenderJson(re)
}
@@ -47,8 +47,9 @@ define("tinymce/pasteplugin/Clipboard", [
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) {
if(reIsOk(ret)) {
// 将图片替换之
var src = urlPrefix + "/" + ret.Item;
var dom = editor.dom
// var src = urlPrefix + "/" + ret.Item;
var src = urlPrefix + "/file/outputImage?fileId=" + ret.Id;
var dom = editor.dom;
for(var i in ids) {
var id = ids[i];
var imgElm = dom.get(id);
+1 -23
View File
@@ -44,26 +44,11 @@ define("tinymce/pasteplugin/Plugin", [
}
}
}
function togglePasteCopyImage() {
if (clipboard.copyImage) {
this.active(false);
clipboard.copyImage = false
} else {
clipboard.copyImage = true;
this.active(true);
if (!userIsInformed2) {
editor.windowManager.alert(
"When copy other site's images (not in leanote) into editor, it will copy the image into your album."
);
userIsInformed2 = true;
}
}
}
self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
clipboard.copyImage = true;
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
@@ -116,13 +101,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text"
});
editor.addButton('pasteCopyImage', {
icon: 'copy',
tooltip: "When Paste other site's image, copy it into my album as public image",
onclick: togglePasteCopyImage,
active: self.clipboard.copyImage === true
});
editor.addMenuItem('pastetext', {
text: 'Paste as text',
+1 -1
View File
@@ -117,4 +117,4 @@
writeScripts();
})(this);
// $hash: e0933a5a75e12f26b54b4e7b86f5bdc2
// $hash: cb0df1bfb67ded475df65e7e75c7998f
+4 -25
View File
@@ -232,8 +232,9 @@ define("tinymce/pasteplugin/Clipboard", [
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) {
if(reIsOk(ret)) {
// 将图片替换之
var src = urlPrefix + "/" + ret.Item;
var dom = editor.dom
// var src = urlPrefix + "/" + ret.Item;
var src = urlPrefix + "/file/outputImage?fileId=" + ret.Id;
var dom = editor.dom;
for(var i in ids) {
var id = ids[i];
var imgElm = dom.get(id);
@@ -1103,26 +1104,11 @@ define("tinymce/pasteplugin/Plugin", [
}
}
}
function togglePasteCopyImage() {
if (clipboard.copyImage) {
this.active(false);
clipboard.copyImage = false
} else {
clipboard.copyImage = true;
this.active(true);
if (!userIsInformed2) {
editor.windowManager.alert(
"When copy other site's images (not in leanote) into editor, it will copy the image into your album."
);
userIsInformed2 = true;
}
}
}
self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
clipboard.copyImage = true;
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
@@ -1175,13 +1161,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text"
});
editor.addButton('pasteCopyImage', {
icon: 'copy',
tooltip: "When Paste other site's image, copy it into my album as public image",
onclick: togglePasteCopyImage,
active: self.clipboard.copyImage === true
});
editor.addMenuItem('pastetext', {
text: 'Paste as text',
+1 -1
View File
@@ -1 +1 @@
!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f<a.length;++f){if(c=g[a[f]]||e(a[f]),!c)throw"module definition dependecy not found: "+a[f];d.push(c)}b.apply(null,d)}function d(a,d,e){if("string"!=typeof a)throw"invalid module definition, module id must be defined and be a string";if(d===b)throw"invalid module definition, dependencies must be specified";if(e===b)throw"invalid module definition, definition function must be specified";c(d,function(){g[a]=e.apply(null,arguments)})}function e(b){for(var c=a,d=b.split(/[.\/]/),e=0;e<d.length;++e){if(!c[d[e]])return;c=c[d[e]]}return c}function f(c){for(var d=0;d<c.length;d++){for(var e=a,f=c[d],h=f.split(/[.\/]/),i=0;i<h.length-1;++i)e[h[i]]===b&&(e[h[i]]={}),e=e[h[i]];e[h[h.length-1]]=g[f]}}var g={};d("tinymce/pasteplugin/Utils",["tinymce/util/Tools","tinymce/html/DomParser","tinymce/html/Schema"],function(a,b,c){function d(b,c){return a.each(c,function(a){b=a.constructor==RegExp?b.replace(a,""):b.replace(a[0],a[1])}),b}function e(d){function e(a){var b=a.name,c=a;if("br"===b)return void(h+="\n");if(i[b]&&(h+=" "),j[b])return void(h+=" ");if(3==a.type&&(h+=a.value),!a.shortEnded&&(a=a.firstChild))do e(a);while(a=a.next);k[b]&&c.next&&(h+="\n","p"==b&&(h+="\n"))}var f=new c,g=new b({},f),h="",i=f.getShortEndedElements(),j=a.makeMap("script noscript style textarea video audio iframe object"," "),k=f.getBlockElements();return e(g.parse(d)),h}return{filter:d,innerText:e}}),d("tinymce/pasteplugin/Clipboard",["tinymce/Env","tinymce/util/VK","tinymce/pasteplugin/Utils"],function(a,b,c){return function(d){function e(a,b){ajaxPost("/file/copyHttpImage",{src:a},function(a){if(reIsOk(a)){var c=urlPrefix+"/"+a.Item,e=d.dom;for(var f in b){var g=b[f],h=e.get(g);e.setAttrib(h,"src",c)}}})}function f(a,b){var c,f=d.dom;if(d.settings.paste_data_images||(a=a.replace(/<img[^>]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(/</g,"&lt;"),b=b.replace(/>/g,"&gt;"),d.insertRawContent(b)}else if(p.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$("<div>"+a+"</div"),n=m.find("img"),o=0;o<n.length;++o){var q=n.eq(o),r=q.attr("src");if(-1==r.indexOf(j)){l++;var s="__LEANOTE_IMAGE_"+l;q.attr("id",s),k[r]?k[r].push(s):k[r]=[s]}}d.insertContent(m.html());for(var r in k){var t=k[r];e(r,t)}}catch(i){d.insertContent(a)}}else d.insertContent(a)}}}function g(a){var b=a;a=d.dom.encode(a).replace(/\r\n/g,"\n");var e,g=d.dom.getParent(d.selection.getStart(),d.dom.isBlock),h=d.settings.forced_root_block;h&&(e=d.dom.createHTML(h,d.settings.forced_root_block_attrs),e=e.substr(0,e.length-3)+">"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"<br>"]]):(a=c.filter(a,[[/\n\n/g,"</p>"+e],[/^(.*<\/p>)(<p>)$/,e+"$1"],[/\n/g,"<br />"]]),-1!=a.indexOf("<p>")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),m=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},r),a.setStyle(m,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(m,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),n=d.selection.getRng(),m.focus(),d.selection.select(m,!0)}function i(){m&&(d.dom.unbind(m),d.dom.remove(m),n&&d.selection.setRng(n)),o=!1,m=n=null}function j(){return m?m.innerHTML:r}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;e<c.types.length;e++){var f=c.types[e];b[f]=c.getData(f)}}return b}function l(){var a=LeaAce.nowIsInAce();return a?(setTimeout(function(){a[0].focus()}),!0):!1}var m,n,o,p=this,q=0,r="%MCEPASTEBIN%";d.on("keydown",function(c){if(!c.isDefaultPrevented()&&(b.metaKeyPressed(c)&&86==c.keyCode||c.shiftKey&&45==c.keyCode)){if(l())return;if(o=c.shiftKey&&86==c.keyCode,c.stopImmediatePropagation(),q=(new Date).getTime(),a.ie&&o)return c.preventDefault(),void d.fire("paste",{ieFake:!0});h()}}),d.on("paste",function(b){if(!l()){var e=k(b),n=(new Date).getTime()-q<100,s="text"==p.pasteFormat||o;n||b.preventDefault(),!a.ie||n&&!b.ieFake||(h(),d.dom.bind(m,"paste",function(a){a.stopPropagation()}),d.getDoc().execCommand("Paste",!1,null),e["text/html"]=j(),i()),setTimeout(function(){var a=j();m&&m.firstChild&&"mcepastebin"===m.firstChild.id&&(s=!0),i(),(a!=r&&n||(a=e["text/html"]||e["text/plain"]||r,a!=r))&&(s?g(e["text/plain"]||c.innerText(a)):f(a,e["text/plain"]))},0);try{}catch(b){}}}),p.pasteHtml=f,p.pasteText=g}}),d("tiLine truncated
!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f<a.length;++f){if(c=g[a[f]]||e(a[f]),!c)throw"module definition dependecy not found: "+a[f];d.push(c)}b.apply(null,d)}function d(a,d,e){if("string"!=typeof a)throw"invalid module definition, module id must be defined and be a string";if(d===b)throw"invalid module definition, dependencies must be specified";if(e===b)throw"invalid module definition, definition function must be specified";c(d,function(){g[a]=e.apply(null,arguments)})}function e(b){for(var c=a,d=b.split(/[.\/]/),e=0;e<d.length;++e){if(!c[d[e]])return;c=c[d[e]]}return c}function f(c){for(var d=0;d<c.length;d++){for(var e=a,f=c[d],h=f.split(/[.\/]/),i=0;i<h.length-1;++i)e[h[i]]===b&&(e[h[i]]={}),e=e[h[i]];e[h[h.length-1]]=g[f]}}var g={};d("tinymce/pasteplugin/Utils",["tinymce/util/Tools","tinymce/html/DomParser","tinymce/html/Schema"],function(a,b,c){function d(b,c){return a.each(c,function(a){b=a.constructor==RegExp?b.replace(a,""):b.replace(a[0],a[1])}),b}function e(d){function e(a){var b=a.name,c=a;if("br"===b)return void(h+="\n");if(i[b]&&(h+=" "),j[b])return void(h+=" ");if(3==a.type&&(h+=a.value),!a.shortEnded&&(a=a.firstChild))do e(a);while(a=a.next);k[b]&&c.next&&(h+="\n","p"==b&&(h+="\n"))}var f=new c,g=new b({},f),h="",i=f.getShortEndedElements(),j=a.makeMap("script noscript style textarea video audio iframe object"," "),k=f.getBlockElements();return e(g.parse(d)),h}return{filter:d,innerText:e}}),d("tinymce/pasteplugin/Clipboard",["tinymce/Env","tinymce/util/VK","tinymce/pasteplugin/Utils"],function(a,b,c){return function(d){function e(a,b){ajaxPost("/file/copyHttpImage",{src:a},function(a){if(reIsOk(a)){var c=urlPrefix+"/file/outputImage?fileId="+a.Id,e=d.dom;for(var f in b){var g=b[f],h=e.get(g);e.setAttrib(h,"src",c)}}})}function f(a,b){var c,f=d.dom;if(d.settings.paste_data_images||(a=a.replace(/<img[^>]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(/</g,"&lt;"),b=b.replace(/>/g,"&gt;"),d.insertRawContent(b)}else if(p.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$("<div>"+a+"</div"),n=m.find("img"),o=0;o<n.length;++o){var q=n.eq(o),r=q.attr("src");if(-1==r.indexOf(j)){l++;var s="__LEANOTE_IMAGE_"+l;q.attr("id",s),k[r]?k[r].push(s):k[r]=[s]}}d.insertContent(m.html());for(var r in k){var t=k[r];e(r,t)}}catch(i){d.insertContent(a)}}else d.insertContent(a)}}}function g(a){var b=a;a=d.dom.encode(a).replace(/\r\n/g,"\n");var e,g=d.dom.getParent(d.selection.getStart(),d.dom.isBlock),h=d.settings.forced_root_block;h&&(e=d.dom.createHTML(h,d.settings.forced_root_block_attrs),e=e.substr(0,e.length-3)+">"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"<br>"]]):(a=c.filter(a,[[/\n\n/g,"</p>"+e],[/^(.*<\/p>)(<p>)$/,e+"$1"],[/\n/g,"<br />"]]),-1!=a.indexOf("<p>")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),m=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},r),a.setStyle(m,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(m,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),n=d.selection.getRng(),m.focus(),d.selection.select(m,!0)}function i(){m&&(d.dom.unbind(m),d.dom.remove(m),n&&d.selection.setRng(n)),o=!1,m=n=null}function j(){return m?m.innerHTML:r}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;e<c.types.length;e++){var f=c.types[e];b[f]=c.getData(f)}}return b}function l(){var a=LeaAce.nowIsInAce();return a?(setTimeout(function(){a[0].focus()}),!0):!1}var m,n,o,p=this,q=0,r="%MCEPASTEBIN%";d.on("keydown",function(c){if(!c.isDefaultPrevented()&&(b.metaKeyPressed(c)&&86==c.keyCode||c.shiftKey&&45==c.keyCode)){if(l())return;if(o=c.shiftKey&&86==c.keyCode,c.stopImmediatePropagation(),q=(new Date).getTime(),a.ie&&o)return c.preventDefault(),void d.fire("paste",{ieFake:!0});h()}}),d.on("paste",function(b){if(!l()){var e=k(b),n=(new Date).getTime()-q<100,s="text"==p.pasteFormat||o;n||b.preventDefault(),!a.ie||n&&!b.ieFake||(h(),d.dom.bind(m,"paste",function(a){a.stopPropagation()}),d.getDoc().execCommand("Paste",!1,null),e["text/html"]=j(),i()),setTimeout(function(){var a=j();m&&m.firstChild&&"mcepastebin"===m.firstChild.id&&(s=!0),i(),(a!=r&&n||(a=e["text/html"]||e["text/plain"]||r,a!=r))&&(s?g(e["text/plain"]||c.innerText(a)):f(a,e["text/plain"]))},0);try{}catch(b){}}}),p.pasteHtml=f,Line truncated