paste image when edit/add shared note
This commit is contained in:
@ -18,7 +18,7 @@ type File struct {
|
||||
}
|
||||
|
||||
// 上传图片 editor
|
||||
// 过时
|
||||
// 过时 已弃用!
|
||||
func (c File) UploadImage(renderHtml string) revel.Result {
|
||||
if renderHtml == "" {
|
||||
renderHtml = "file/image.html"
|
||||
@ -39,12 +39,36 @@ func (c File) UploadBlogLogo() revel.Result {
|
||||
return c.UploadImage("file/blog_logo.html");
|
||||
}
|
||||
|
||||
// 拖拉上传, pasteImage
|
||||
func (c File) UploadImageJson(renderHtml, from string) revel.Result {
|
||||
// 弃用
|
||||
func (c File) UploadImageJson(from, noteId string) revel.Result {
|
||||
re := c.uploadImage(from, "");
|
||||
return c.RenderJson(re)
|
||||
}
|
||||
|
||||
// 拖拉上传, pasteImage
|
||||
// noteId 是为了判断是否是协作的note, 如果是则需要复制一份到note owner中
|
||||
func (c File) PasteImage(noteId string) revel.Result {
|
||||
re := c.uploadImage("pasteImage", "");
|
||||
|
||||
userId := c.GetUserId()
|
||||
note := noteService.GetNoteById(noteId)
|
||||
if note.UserId != "" {
|
||||
noteUserId := note.UserId.Hex()
|
||||
if noteUserId != userId {
|
||||
// 是否是有权限协作的
|
||||
if shareService.HasUpdatePerm(noteUserId, userId, noteId) {
|
||||
// 复制图片之, 图片复制给noteUserId
|
||||
_, re.Id = fileService.CopyImage(userId, re.Id, noteUserId)
|
||||
} else {
|
||||
// 怎么可能在这个笔记下paste图片呢?
|
||||
// 正常情况下不会
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.RenderJson(re)
|
||||
}
|
||||
|
||||
// leaui image plugin
|
||||
func (c File) UploadImageLeaui(albumId string) revel.Result {
|
||||
re := c.uploadImage("", albumId);
|
||||
@ -60,7 +84,7 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
|
||||
var Ok = false
|
||||
|
||||
defer func() {
|
||||
re.Id = fileId
|
||||
re.Id = fileId // 只是id, 没有其它信息
|
||||
re.Code = resultCode
|
||||
re.Msg = resultMsg
|
||||
re.Ok = Ok
|
||||
|
@ -287,6 +287,7 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
var c = new FormData;
|
||||
c.append("from", "pasteImage");
|
||||
c.append("file", blob);
|
||||
c.append("noteId", Note.curNoteId); // life
|
||||
// var d;
|
||||
// d = $.ajaxSettings.xhr();
|
||||
// d.withCredentials = i;var d = {};
|
||||
@ -296,10 +297,10 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
var dom = editor.dom;
|
||||
var d = {};
|
||||
d.id = '__mcenew';
|
||||
d.src = "http://leanote.com/images/loading-24.gif";
|
||||
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
|
||||
editor.insertContent(dom.createHTML('img', d));
|
||||
var imgElm = dom.get('__mcenew');
|
||||
$.ajax({url: "/file/uploadImageJson", contentType:false, processData:false , data: c, type: "POST"}
|
||||
$.ajax({url: "/file/pasteImage", contentType:false, processData:false , data: c, type: "POST"}
|
||||
).done(function(re) {
|
||||
if(!re || typeof re != "object" || !re.Ok) {
|
||||
// 删除
|
||||
@ -307,7 +308,9 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
return;
|
||||
}
|
||||
// 这里, 如果图片宽度过大, 这里设置成500px
|
||||
getImageSize(re.Id, function(wh) {
|
||||
var urlPrefix = window.location.protocol + "//" + window.location.host;
|
||||
var src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
|
||||
getImageSize(src, function(wh) {
|
||||
// life 4/25
|
||||
if(wh && wh.width) {
|
||||
if(wh.width > 600) {
|
||||
@ -316,7 +319,7 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
d.width = wh.width;
|
||||
dom.setAttrib(imgElm, 'width', d.width);
|
||||
}
|
||||
dom.setAttrib(imgElm, 'src', re.Id);
|
||||
dom.setAttrib(imgElm, 'src', src);
|
||||
});
|
||||
dom.setAttrib(imgElm, 'id', null);
|
||||
});
|
||||
|
@ -472,6 +472,7 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
var c = new FormData;
|
||||
c.append("from", "pasteImage");
|
||||
c.append("file", blob);
|
||||
c.append("noteId", Note.curNoteId);
|
||||
// var d;
|
||||
// d = $.ajaxSettings.xhr();
|
||||
// d.withCredentials = i;var d = {};
|
||||
@ -481,10 +482,10 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
var dom = editor.dom;
|
||||
var d = {};
|
||||
d.id = '__mcenew';
|
||||
d.src = "http://leanote.com/images/loading-24.gif";
|
||||
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
|
||||
editor.insertContent(dom.createHTML('img', d));
|
||||
var imgElm = dom.get('__mcenew');
|
||||
$.ajax({url: "/file/uploadImageJson", contentType:false, processData:false , data: c, type: "POST"}
|
||||
$.ajax({url: "/file/pasteImage", contentType:false, processData:false , data: c, type: "POST"}
|
||||
).done(function(re) {
|
||||
if(!re || typeof re != "object" || !re.Ok) {
|
||||
// 删除
|
||||
@ -492,7 +493,9 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
return;
|
||||
}
|
||||
// 这里, 如果图片宽度过大, 这里设置成500px
|
||||
getImageSize(re.Id, function(wh) {
|
||||
var urlPrefix = window.location.protocol + "//" + window.location.host;
|
||||
var src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
|
||||
getImageSize(src, function(wh) {
|
||||
// life 4/25
|
||||
if(wh && wh.width) {
|
||||
if(wh.width > 600) {
|
||||
@ -501,7 +504,7 @@ define("tinymce/pasteplugin/Clipboard", [
|
||||
d.width = wh.width;
|
||||
dom.setAttrib(imgElm, 'width', d.width);
|
||||
}
|
||||
dom.setAttrib(imgElm, 'src', re.Id);
|
||||
dom.setAttrib(imgElm, 'src', src);
|
||||
});
|
||||
dom.setAttrib(imgElm, 'id', null);
|
||||
});
|
||||
|
Reference in New Issue
Block a user