relative image url/fix conflict when upload attachment again

This commit is contained in:
lealife
2016-12-24 15:16:23 +08:00
parent f49624d3eb
commit a8dd578624
24 changed files with 130 additions and 106 deletions

@ -8,8 +8,9 @@ import (
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
"os" "os"
"os/exec" "os/exec"
"strings" // "strings"
"time" "time"
"regexp"
// "github.com/leanote/leanote/app/types" // "github.com/leanote/leanote/app/types"
// "io/ioutil" // "io/ioutil"
// "fmt" // "fmt"
@ -158,11 +159,31 @@ func (c ApiNote) fixPostNotecontent(noteOrContent *info.ApiNote) {
if noteOrContent.Content == "" { if noteOrContent.Content == "" {
return return
} }
files := noteOrContent.Files files := noteOrContent.Files
if files != nil && len(files) > 0 { if files != nil && len(files) > 0 {
for _, file := range files { for _, file := range files {
if file.LocalFileId != "" { if file.LocalFileId != "" {
noteOrContent.Content = strings.Replace(noteOrContent.Content, "fileId="+file.LocalFileId, "fileId="+file.FileId, -1) LogJ(file)
if !file.IsAttach {
reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getImage\?fileId=`+file.LocalFileId)
// Log(reg)
noteOrContent.Content = reg.ReplaceAllString(noteOrContent.Content, `"/api/file/getImage?fileId=`+file.FileId)
// // "http://a.com/api/file/getImage?fileId=localId" => /api/file/getImage?fileId=serverId
// noteOrContent.Content = strings.Replace(noteOrContent.Content,
// baseUrl + "/api/file/getImage?fileId="+file.LocalFileId,
// "/api/file/getImage?fileId="+file.FileId, -1)
} else {
reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getAttach\?fileId=`+file.LocalFileId)
Log(reg)
noteOrContent.Content = reg.ReplaceAllString(noteOrContent.Content, `"/api/file/getAttach?fileId=`+file.FileId)
/*
noteOrContent.Content = strings.Replace(noteOrContent.Content,
baseUrl + "/api/file/getAttach?fileId="+file.LocalFileId,
"/api/file/getAttach?fileId="+file.FileId, -1)
*/
}
} }
} }
} }
@ -352,6 +373,7 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
Log("conflict") Log("conflict")
return c.RenderJson(re) return c.RenderJson(re)
} }
Log("没有冲突")
// 如果传了files // 如果传了files
// TODO 测试 // TODO 测试

@ -119,6 +119,7 @@ func (this *AttachService) DeleteAllAttachs(noteId, userId string) bool {
} }
// delete attach // delete attach
// 删除附件为什么要incrNoteUsn ? 因为可能没有内容要修改的
func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) { func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) {
attach := info.Attach{} attach := info.Attach{}
db.Get(db.Attachs, attachId, &attach) db.Get(db.Attachs, attachId, &attach)

@ -415,9 +415,15 @@ func (this *NoteService) UpdateNote(updatedUserId, noteId string, needUpdate bso
} }
} }
/*
// 这里不再判断, 因为controller已经判断了, 删除附件会新增, 所以不用判断
if usn > 0 && note.Usn != usn { if usn > 0 && note.Usn != usn {
Log("有冲突!!")
Log(note.Usn)
Log(usn)
return false, "conflict", 0 return false, "conflict", 0
} }
*/
// 是否已自定义 // 是否已自定义
if note.IsBlog && note.HasSelfDefined { if note.IsBlog && note.HasSelfDefined {
@ -1017,6 +1023,8 @@ func (this *NoteService) FixContentBad(content string, isMarkdown bool) string {
return content return content
} }
// 得到笔记的内容, 此时将笔记内的链接转成标准的Leanote Url
// 将笔记的图片, 附件链接转换成 site.url/file/getImage?fileId=xxx, site.url/file/getAttach?fileId=xxxx
// 性能更好, 5倍的差距 // 性能更好, 5倍的差距
func (this *NoteService) FixContent(content string, isMarkdown bool) string { func (this *NoteService) FixContent(content string, isMarkdown bool) string {
baseUrl := configService.GetSiteUrl() baseUrl := configService.GetSiteUrl()
@ -1029,12 +1037,19 @@ func (this *NoteService) FixContent(content string, isMarkdown bool) string {
} else { } else {
baseUrlPattern = strings.Replace(baseUrl, "http://", "https*://", 1) baseUrlPattern = strings.Replace(baseUrl, "http://", "https*://", 1)
} }
baseUrlPattern = "(?:" + baseUrlPattern + ")*"
Log(baseUrlPattern)
patterns := []map[string]string{ patterns := []map[string]string{
map[string]string{"src": "src", "middle": "/api/file/getImage", "param": "fileId", "to": "getImage?fileId="},
map[string]string{"src": "src", "middle": "/file/outputImage", "param": "fileId", "to": "getImage?fileId="}, map[string]string{"src": "src", "middle": "/file/outputImage", "param": "fileId", "to": "getImage?fileId="},
map[string]string{"src": "href", "middle": "/attach/download", "param": "attachId", "to": "getAttach?fileId="}, map[string]string{"src": "href", "middle": "/attach/download", "param": "attachId", "to": "getAttach?fileId="},
map[string]string{"src": "href", "middle": "/api/file/getAtach", "param": "fileId", "to": "getAttach?fileId="},
// 该链接已失效, 不再支持 // 该链接已失效, 不再支持
map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="}, // map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="},
} }
for _, eachPattern := range patterns { for _, eachPattern := range patterns {
@ -1056,6 +1071,8 @@ func (this *NoteService) FixContent(content string, isMarkdown bool) string {
reg2, _ = regexp.Compile("<a(?:[^>]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`) reg2, _ = regexp.Compile("<a(?:[^>]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`)
} }
Log(reg2)
content = reg.ReplaceAllStringFunc(content, func(str string) string { content = reg.ReplaceAllStringFunc(content, func(str string) string {
// str=这样的 // str=这样的
// <img src="http://localhost:9000/file/outputImage?fileId=563d706e99c37b48e0000001" alt="" data-mce-src="http://localhost:9000/file/outputImage?fileId=563d706e99c37b48e0000002"> // <img src="http://localhost:9000/file/outputImage?fileId=563d706e99c37b48e0000001" alt="" data-mce-src="http://localhost:9000/file/outputImage?fileId=563d706e99c37b48e0000002">

@ -0,0 +1,32 @@
package tests
import (
"github.com/leanote/leanote/app/db"
"github.com/revel/revel"
"testing"
// . "github.com/leanote/leanote/app/lea"
"github.com/leanote/leanote/app/service"
// "regexp"
// "gopkg.in/mgo.v2"
// "fmt"
// "strings"
)
// 可在server端调试
func init() {
revel.Init("dev", "github.com/leanote/leanote", "/Users/life/Documents/Go/package_base/src")
db.Init("mongodb://localhost:27017/leanote", "leanote")
service.InitService()
service.ConfigS.InitGlobalConfigs()
}
func TestApiFixNoteContent2(t *testing.T) {
note2 := service.NoteS.GetNote("585df83771c1b17e8a000000", "585df81199c37b6176000004")
note := service.NoteS.GetNoteContent("585df83771c1b17e8a000000", "585df81199c37b6176000004")
contentFixed := service.NoteS.FixContent(note.Content, false)
t.Log(note2.Title)
t.Log(note.Content)
t.Log(contentFixed)
}

26
app/tests/reg_test.go Normal file

@ -0,0 +1,26 @@
package tests
import (
// "github.com/leanote/leanote/app/db"
"testing"
// . "github.com/leanote/leanote/app/lea"
// "github.com/leanote/leanote/app/service"
// "gopkg.in/mgo.v2"
// "fmt"
"regexp"
)
// 测试登录
func TestReg(t *testing.T) {
a := `<a href="http://localhost:9000/api/file/getAttach?fileId=585e0e9c270a35609300000c" target="_blank" data-mce-href="http://localhost:9000/api/file/getAttach?fileId=585e0e9c270a35609300000c">proxy.go</a>`
reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getAttach\?fileId=585e0e9c270a35609300000c`)
a2 := reg.ReplaceAllString(a, `"`)
t.Log(a2)
}

@ -161,6 +161,6 @@ var UrlPrefix = '{{.siteUrl}}';
<script src="/public/album/js/main.js"></script> <script src="/public/album/js/main.js"></script>
--> -->
<script src="/public/album/js/main.all.js"></script> <script src="/public/album/js/main.all.js?i=2"></script>
</html> </html>

@ -9,7 +9,7 @@ SP=$(cd "$(dirname "$0")"; pwd)
tmp="/Users/life/Desktop/leanote_release" tmp="/Users/life/Desktop/leanote_release"
# version # version
V="v2.0" V="v2.1"
##================================= ##=================================
# 1. 先build 成 3个平台, 2种bit = 6种 # 1. 先build 成 3个平台, 2种bit = 6种

File diff suppressed because one or more lines are too long

@ -8,7 +8,7 @@ function retIsOk(ret) {
return false; return false;
} }
var urlPrefix = UrlPrefix; var urlPrefix = '';
var getMsg = parent.getMsg; var getMsg = parent.getMsg;
if (!getMsg) { if (!getMsg) {
getMsg = function(msg) { getMsg = function(msg) {

File diff suppressed because one or more lines are too long

@ -523,8 +523,8 @@ function initEditor() {
// fix TinyMCE Removes site base url // fix TinyMCE Removes site base url
// http://stackoverflow.com/questions/3360084/tinymce-removes-site-base-urls // http://stackoverflow.com/questions/3360084/tinymce-removes-site-base-urls
convert_urls:true, convert_urls: false, // true会将url变成../api/
relative_urls:false, relative_urls: true,
remove_script_host:false, remove_script_host:false,
selector : "#editorContent", selector : "#editorContent",

@ -1 +1 @@
var MSG={"noTag":"Keine Tags","saveSuccess":"Speichern erfolgreich","none":"Keine","like":"Gefällt mir","unlike":"Gefällt mir nicht mehr","delete":"Löschen","cancel":"Abbrechen","confirm":"Bestätigen","chooseReason":"Grund angeben","reportSuccess":"Erfolg","error":"Fehler","reportComment?":"Kommentar?","reportBlog?":"Blog?","confirmDeleteComment":"Wirklich löschen?","scanQRCode":"weichat öffnen und QR Code scannen","justNow":"Jetzt","minutesAgo":"Minuten","hoursAgo":"Stunden","daysAgo":"Tage","weeksAgo":"Wochen","monthsAgo":"Monate"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;} var MSG={"noTag":"Keine Tags","saveSuccess":"Speichern erfolgreich","none":"Keine","like":"Gefällt mir","unlike":"Gefällt mir nicht mehr","delete":"Löschen","cancel":"Abbrechen","confirm":"Bestätigen","chooseReason":"请选择举报理由","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","error":"Error","reportComment?":"举报该评论?","reportBlog?":"举报该博客?","confirmDeleteComment":"Sind Sie sicher?","scanQRCode":"Öffnen Sie weichat und scannen den QR Code","justNow":"Jetz","minutesAgo":"Minuten","hoursAgo":"Stunden","daysAgo":"Tage","weeksAgo":"Wochen","monthsAgo":"Monate"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;}

@ -1 +1 @@
var MSG={"noTag":"No tag","saveSuccess":"Save success","none":"None","like":"Like","unlike":"Unlike","delete":"Delete","cancel":"Cancel","confirm":"Confirm","chooseReason":"请选择举报理由","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","error":"Error","reportComment?":"举报该评论?","reportBlog?":"举报该博客?","confirmDeleteComment":"Are you sure?","scanQRCode":"Open weichat and scan the QR code","justNow":"Just now","minutesAgo":"minutes ago","hoursAgo":"hours ago","daysAgo":"days ago","weeksAgo":"weeks ago","monthsAgo":"months ago"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;} var MSG={"noTag":"No tag","saveSuccess":"Save success","none":"None","like":"Like","unlike":"Unlike","delete":"Delete","cancel":"Cancel","confirm":"Confirm","chooseReason":"Select report reason","reportSuccess":"Reporting success, we will notify the author, thank you for your monitor","error":"Error","reportComment?":"Report this comment?","reportBlog?":"Report this blog?","confirmDeleteComment":"Are you sure?","scanQRCode":"Open weichat and scan the QR code","justNow":"Just now","minutesAgo":"minutes ago","hoursAgo":"hours ago","daysAgo":"days ago","weeksAgo":"weeks ago","monthsAgo":"months ago"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,6 +1,5 @@
// for editor. // for editor.
// drag image to editor // drag image to editor
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
define('editor_drop_paste', ['fileupload'], function() { define('editor_drop_paste', ['fileupload'], function() {
// 在toggle成pre或ace时 // 在toggle成pre或ace时
@ -125,8 +124,7 @@ define('editor_drop_paste', ['fileupload'], function() {
(function(data) { (function(data) {
ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) { ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) {
if(reIsOk(re) && re.Id) { if(reIsOk(re) && re.Id) {
var urlPrefix = window.location.protocol + "//" + window.location.host; data.src = "/api/file/getImage?fileId=" + re.Id;
data.src = urlPrefix + "/api/file/getImage?fileId=" + re.Id;
} }
renderImage(data); renderImage(data);
}); });
@ -180,7 +178,7 @@ define('editor_drop_paste', ['fileupload'], function() {
if (data.result.Ok == true) { if (data.result.Ok == true) {
data.context.remove(); data.context.remove();
// life // life
var data2 = {src: urlPrefix + "/api/file/getImage?fileId=" + data.result.Id} var data2 = {src: "/api/file/getImage?fileId=" + data.result.Id}
insertImage(data2); insertImage(data2);
} else { } else {
data.context.empty(); data.context.empty();
@ -339,80 +337,20 @@ define('editor_drop_paste', ['fileupload'], function() {
data.process = process; data.process = process;
var jqXHR = data.submit(); var jqXHR = data.submit();
}, 20); }, 20);
/*
d.id = '__mcenew' + (new Date()).getTime();
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
var img = '<img src="' + d.src + '" id="' + d.id + '" />';
editor.insertContent(img);
var imgElm = $(d.id);
data.imgId = d.id;
data.context = imgElm;
*/
/*
// 上传之
var c = new FormData;
c.append("from", "pasteImage");
// var d;
// d = $.ajaxSettings.xhr();
// d.withCredentials = i;var d = {};
// 先显示loading...
var editor = tinymce.EditorManager.activeEditor;
var dom = editor.dom;
var d = {};
d.id = '__mcenew';
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
editor.insertContent(dom.createHTML('img', d));
var imgElm = dom.get('__mcenew');
$.ajax({url: "/file/pasteImage", contentType:false, processData:false , data: c, type: "POST"}
).done(function(re) {
if(!re || typeof re != "object" || !re.Ok) {
// 删除
dom.remove(imgElm);
return;
}
// 这里, 如果图片宽度过大, 这里设置成500px
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
var src = urlPrefix + "/api/file/getImage?fileId=" + re.Id;
getImageSize(src, function(wh) {
// life 4/25
if(wh && wh.width) {
if(wh.width > 600) {
wh.width = 600;
}
d.width = wh.width;
dom.setAttrib(imgElm, 'width', d.width);
}
dom.setAttrib(imgElm, 'src', src);
});
dom.setAttrib(imgElm, 'id', null);
});
};
reader.readAsDataURL(blob);
*/
}, },
done: function(e, data) { done: function(e, data) {
if (data.result.Ok == true) { if (data.result.Ok == true) {
// 这里, 如果图片宽度过大, 这里设置成500px // 这里, 如果图片宽度过大, 这里设置成500px
var re = data.result; var re = data.result;
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; var src = "/api/file/getImage?fileId=" + re.Id;
var src = urlPrefix + "/api/file/getImage?fileId=" + re.Id;
if(curNote && !curNote.IsMarkdown) { if(curNote && !curNote.IsMarkdown) {
data.process.replace(src); data.process.replace(src);
} else { } else {
MD && MD.insertLink(src, 'title', true); MD && MD.insertLink(src, 'title', true);
} }
/*
getImageSize(src, function() {
$img.attr('src', src);
$img.removeAttr('id');
});
*/
} else { } else {
data.process.remove(); data.process.remove();
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -110,13 +110,8 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
var data = datas[i]; var data = datas[i];
var src = data.src; var src = data.src;
// the network image // the network image
var trueSrc; var trueSrc = src;
if(src.indexOf("http://") != -1 || src.indexOf("https://") != -1) { data.src = src;
trueSrc = src;
} else {
trueSrc = url + "/" + src;
}
data.src = trueSrc;
var renderImage = function(data) { var renderImage = function(data) {
// 这里, 如果图片宽度过大, 这里设置成500px // 这里, 如果图片宽度过大, 这里设置成500px
@ -125,7 +120,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
var imgElm; var imgElm;
// 先显示loading... // 先显示loading...
d.id = '__mcenew' + i; d.id = '__mcenew' + i;
d.src = "http://leanote.com/images/loading-24.gif"; d.src = "/images/loading-24.gif";
imgElm = dom.createHTML('img', d); imgElm = dom.createHTML('img', d);
editor.insertContent(imgElm); editor.insertContent(imgElm);
imgElm = dom.get(d.id); imgElm = dom.get(d.id);
@ -164,8 +159,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
(function(data) { (function(data) {
ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) { ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) {
if(reIsOk(re) && re.Id) { if(reIsOk(re) && re.Id) {
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; data.src = "/api/file/getImage?fileId=" + re.Id;
data.src = urlPrefix + "/api/file/getImage?fileId=" + re.Id;
} }
renderImage(data); renderImage(data);
}); });

@ -1 +1 @@
var LEAUI_DATAS=[];tinymce.PluginManager.add("leaui_image",function(a,b){function c(a,b){function c(a,c){d.parentNode.removeChild(d),b({width:a,height:c})}var d=document.createElement("img");d.onload=function(){c(d.clientWidth,d.clientHeight)},d.onerror=function(){c()},d.src=a;var e=d.style;e.visibility="hidden",e.position="fixed",e.bottom=e.left=0,e.width=e.height="auto",document.body.appendChild(d)}function d(){function d(){var a='<iframe id="leauiIfr" src="/album/index?'+(new Date).getTime()+'" frameborder="0"></iframe>';return a}var e=a.dom,f=a.selection.getContent(),g=/<img.*?\/>/g,h=f.match(g),i=document.createElement("p"),j=[];for(var k in h){i.innerHTML=h[k];var l=i.firstChild;if(l&&"IMG"==l.nodeName){var m={};m.src=e.getAttrib(l,"data-src")||e.getAttrib(l,"src"),m.width=e.getAttrib(l,"width"),m.height=e.getAttrib(l,"height"),m.title=e.getAttrib(l,"title"),j.push(m)}}LEAUI_DATAS=j;var n=$(document).width()-10;n>805&&(n=805);var o=$(document).height()-100;o>365&&(o=365),win=a.windowManager.open({title:"Image",width:n,height:o,html:d(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert Image",subtype:"primary",onclick:function(d){for(var f=document.getElementById("leauiIfr").contentWindow,g=f.document.getElementById("preview"),h=g.childNodes,i=[],j=0;j<h.length;++j){var d=h[j];if(d.firstChild&&"IMG"==d.firstChild.nodeName){var k=d.firstChild,l={};l.src=k.getAttribute("src"),l.width=k.getAttribute("data-width"),l.height=k.getAttribute("data-height"),l.title=k.getAttribute("data-title"),i.push(l)}}for(var j in i){var m,n=i[j],o=n.src;m=-1!=o.indexOf("http://")||-1!=o.indexOf("https://")?o:b+"/"+o,n.src=m;var p=function(b){var d=function(b,c){var d,f={};return f.id="__mcenew"+c,f.src="http://leanote.com/images/loading-24.gif",d=e.createHTML("img",f),a.insertContent(d),d=e.get(f.id),function(a){a&&a.width&&(a.width>600&&(a.width=600),b.width=a.width),e.setAttrib(d,"src",b.src),e.setAttrib(d,"title",b.title),e.setAttrib(d,"id",null)}}(b,j);c(b.src,d)},q="";if(fileIds=m.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(q=fileIds[1]),q){var r;Note&&Note.getCurNote&&(r=Note.getCurNote()),r&&r.UserId!=UserInfo.UserId?!function(a){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:q,toUserId:r.UserId},function(b){if(reIsOk(b)&&b.Id){var c=UrlPrefix;a.src=c+"/api/file/getImage?fileId="+b.Id}p(a)})}(n):p(n)}else p(n)}this.parent().parent().close()}}]})}a.addButton("leaui_image",{icon:"image",tooltip:"Insert/edit image",onclick:d,stateSelector:"img:not([data-mind-json])"}),a.addMenuItem("leaui_image",{icon:"image",text:"Insert image",onclick:d,context:"insert",prependToContext:!0});var e=!1;a.on("dragstart",function(a){LEA.readOnly&&(a.preventDefault(),a.stopPropagation()),e=!0}),a.on("dragend",function(a){e=!1}),a.on("dragover",function(a){e&&(a.preventDefault(),a.stopPropagation())})}); var LEAUI_DATAS=[];tinymce.PluginManager.add("leaui_image",function(a,b){function c(a,b){function c(a,c){d.parentNode.removeChild(d),b({width:a,height:c})}var d=document.createElement("img");d.onload=function(){c(d.clientWidth,d.clientHeight)},d.onerror=function(){c()},d.src=a;var e=d.style;e.visibility="hidden",e.position="fixed",e.bottom=e.left=0,e.width=e.height="auto",document.body.appendChild(d)}function d(){function b(){var a='<iframe id="leauiIfr" src="/album/index?'+(new Date).getTime()+'" frameborder="0"></iframe>';return a}var d=a.dom,e=a.selection.getContent(),f=/<img.*?\/>/g,g=e.match(f),h=document.createElement("p"),i=[];for(var j in g){h.innerHTML=g[j];var k=h.firstChild;if(k&&"IMG"==k.nodeName){var l={};l.src=d.getAttrib(k,"data-src")||d.getAttrib(k,"src"),l.width=d.getAttrib(k,"width"),l.height=d.getAttrib(k,"height"),l.title=d.getAttrib(k,"title"),i.push(l)}}LEAUI_DATAS=i;var m=$(document).width()-10;m>805&&(m=805);var n=$(document).height()-100;n>365&&(n=365),win=a.windowManager.open({title:"Image",width:m,height:n,html:b(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert Image",subtype:"primary",onclick:function(b){for(var e=document.getElementById("leauiIfr").contentWindow,f=e.document.getElementById("preview"),g=f.childNodes,h=[],i=0;i<g.length;++i){var b=g[i];if(b.firstChild&&"IMG"==b.firstChild.nodeName){var j=b.firstChild,k={};k.src=j.getAttribute("src"),k.width=j.getAttribute("data-width"),k.height=j.getAttribute("data-height"),k.title=j.getAttribute("data-title"),h.push(k)}}for(var i in h){var l=h[i],m=l.src,n=m;l.src=m;var o=function(b){var e=function(b,c){var e,f={};return f.id="__mcenew"+c,f.src="/images/loading-24.gif",e=d.createHTML("img",f),a.insertContent(e),e=d.get(f.id),function(a){a&&a.width&&(a.width>600&&(a.width=600),b.width=a.width),d.setAttrib(e,"src",b.src),d.setAttrib(e,"title",b.title),d.setAttrib(e,"id",null)}}(b,i);c(b.src,e)},p="";if(fileIds=n.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(p=fileIds[1]),p){var q;Note&&Note.getCurNote&&(q=Note.getCurNote()),q&&q.UserId!=UserInfo.UserId?!function(a){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:p,toUserId:q.UserId},function(b){reIsOk(b)&&b.Id&&(a.src="/api/file/getImage?fileId="+b.Id),o(a)})}(l):o(l)}else o(l)}this.parent().parent().close()}}]})}a.addButton("leaui_image",{icon:"image",tooltip:"Insert/edit image",onclick:d,stateSelector:"img:not([data-mind-json])"}),a.addMenuItem("leaui_image",{icon:"image",text:"Insert image",onclick:d,context:"insert",prependToContext:!0});var e=!1;a.on("dragstart",function(a){LEA.readOnly&&(a.preventDefault(),a.stopPropagation()),e=!0}),a.on("dragend",function(a){e=!1}),a.on("dragover",function(a){e&&(a.preventDefault(),a.stopPropagation())})});

@ -117,4 +117,4 @@
writeScripts(); writeScripts();
})(this); })(this);
// $hash: fb4edcbc9aa7f82a3fc6e0a6a3486fec // $hash: f4f33bf34dc8356762ead5554b3b4576

@ -39899,13 +39899,8 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
var data = datas[i]; var data = datas[i];
var src = data.src; var src = data.src;
// the network image // the network image
var trueSrc; var trueSrc = src;
if(src.indexOf("http://") != -1 || src.indexOf("https://") != -1) { data.src = src;
trueSrc = src;
} else {
trueSrc = url + "/" + src;
}
data.src = trueSrc;
var renderImage = function(data) { var renderImage = function(data) {
// 这里, 如果图片宽度过大, 这里设置成500px // 这里, 如果图片宽度过大, 这里设置成500px
@ -39914,7 +39909,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
var imgElm; var imgElm;
// 先显示loading... // 先显示loading...
d.id = '__mcenew' + i; d.id = '__mcenew' + i;
d.src = "http://leanote.com/images/loading-24.gif"; d.src = "/images/loading-24.gif";
imgElm = dom.createHTML('img', d); imgElm = dom.createHTML('img', d);
editor.insertContent(imgElm); editor.insertContent(imgElm);
imgElm = dom.get(d.id); imgElm = dom.get(d.id);
@ -39953,8 +39948,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
(function(data) { (function(data) {
ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) { ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) {
if(reIsOk(re) && re.Id) { if(reIsOk(re) && re.Id) {
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; data.src = "/api/file/getImage?fileId=" + re.Id;
data.src = urlPrefix + "/api/file/getImage?fileId=" + re.Id;
} }
renderImage(data); renderImage(data);
}); });

File diff suppressed because one or more lines are too long