update images upload (#944)

* update images upload

* modify js res.url
This commit is contained in:
hotqin888 2024-06-03 10:58:07 +08:00 committed by GitHub
parent 397dced5ce
commit db620be8df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 331 additions and 279 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"image/png" "image/png"
"io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -487,156 +488,211 @@ func (c *DocumentController) Upload() {
name := "editormd-file-file" name := "editormd-file-file"
file, moreFile, err := c.GetFile(name) // file, moreFile, err := c.GetFile(name)
if err == http.ErrMissingFile || moreFile == nil { // if err == http.ErrMissingFile || moreFile == nil {
// name = "editormd-image-file"
// file, moreFile, err = c.GetFile(name)
// if err == http.ErrMissingFile || moreFile == nil {
// c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_empty"))
// return
// }
// }
// ****3xxx
files, err := c.GetFiles(name)
if err == http.ErrMissingFile {
name = "editormd-image-file" name = "editormd-image-file"
file, moreFile, err = c.GetFile(name) files, err = c.GetFiles(name)
if err == http.ErrMissingFile || moreFile == nil { if err == http.ErrMissingFile {
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_empty")) c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_empty"))
return return
} }
} }
if err != nil { // if err != nil {
c.JsonResult(6002, err.Error()) // http.Error(w, err.Error(), http.StatusNoContent)
} // return
// }
// jMap := make(map[string]interface{})
// s := []map[int]interface{}{}
result2 := []map[string]interface{}{}
for i, _ := range files {
//for each fileheader, get a handle to the actual file
file, err := files[i].Open()
defer file.Close() defer file.Close()
// if err != nil {
type Size interface { // http.Error(w, err.Error(), http.StatusInternalServerError)
Size() int64 // return
} // }
// //create destination file making sure the path is writeable.
if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() { // dst, err := os.Create("upload/" + files[i].Filename)
c.JsonResult(6009, i18n.Tr(c.Lang, "message.upload_file_size_limit")) // defer dst.Close()
} // if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
ext := filepath.Ext(moreFile.Filename) // return
//文件必须带有后缀名 // }
if ext == "" { // //copy the uploaded file to the destination file
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_type_error")) // if _, err := io.Copy(dst, file); err != nil {
} // http.Error(w, err.Error(), http.StatusInternalServerError)
//如果文件类型设置为 * 标识不限制文件类型 // return
if conf.IsAllowUploadFileExt(ext) == false { // }
c.JsonResult(6004, i18n.Tr(c.Lang, "message.upload_file_type_error")) // }
} // ****
bookId := 0
// 如果是超级管理员,则不判断权限
if c.Member.IsAdministrator() {
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil { if err != nil {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.doc_not_exist_or_no_permit")) c.JsonResult(6002, err.Error())
} }
bookId = book.BookId // defer file.Close()
} else {
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
if err != nil { type Size interface {
logs.Error("DocumentController.Edit => ", err) Size() int64
if err == orm.ErrNoRows { }
// if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
if conf.GetUploadFileSize() > 0 && files[i].Size > conf.GetUploadFileSize() {
c.JsonResult(6009, i18n.Tr(c.Lang, "message.upload_file_size_limit"))
}
// ext := filepath.Ext(moreFile.Filename)
ext := filepath.Ext(files[i].Filename)
//文件必须带有后缀名
if ext == "" {
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_type_error"))
}
//如果文件类型设置为 * 标识不限制文件类型
if conf.IsAllowUploadFileExt(ext) == false {
c.JsonResult(6004, i18n.Tr(c.Lang, "message.upload_file_type_error"))
}
bookId := 0
// 如果是超级管理员,则不判断权限
if c.Member.IsAdministrator() {
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.doc_not_exist_or_no_permit"))
}
bookId = book.BookId
} else {
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
if err != nil {
logs.Error("DocumentController.Edit => ", err)
if err == orm.ErrNoRows {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission"))
}
c.JsonResult(6001, err.Error())
}
// 如果没有编辑权限
if book.RoleId != conf.BookEditor && book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission")) c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission"))
} }
c.JsonResult(6001, err.Error()) bookId = book.BookId
} }
// 如果没有编辑权限 if docId > 0 {
if book.RoleId != conf.BookEditor && book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder { doc, err := models.NewDocument().Find(docId)
c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission")) if err != nil {
c.JsonResult(6007, i18n.Tr(c.Lang, "message.doc_not_exist"))
}
if doc.BookId != bookId {
c.JsonResult(6008, i18n.Tr(c.Lang, "message.doc_not_belong_project"))
}
} }
bookId = book.BookId fileName := "m_" + cryptil.UniqueId() + "_r"
} filePath := filepath.Join(conf.WorkingDirectory, "uploads", identify)
if docId > 0 { //将图片和文件分开存放
doc, err := models.NewDocument().Find(docId) // if filetil.IsImageExt(moreFile.Filename) {
if err != nil { if filetil.IsImageExt(files[i].Filename) {
c.JsonResult(6007, i18n.Tr(c.Lang, "message.doc_not_exist")) filePath = filepath.Join(filePath, "images", fileName+ext)
} else {
filePath = filepath.Join(filePath, "files", fileName+ext)
} }
if doc.BookId != bookId { path := filepath.Dir(filePath)
c.JsonResult(6008, i18n.Tr(c.Lang, "message.doc_not_belong_project"))
}
}
fileName := "m_" + cryptil.UniqueId() + "_r" _ = os.MkdirAll(path, os.ModePerm)
filePath := filepath.Join(conf.WorkingDirectory, "uploads", identify)
//将图片和文件分开存放 // err = c.SaveToFile(name, filePath) // frome beego controller.go: savetofile it only operates the first one of mutil-upload form file field.
if filetil.IsImageExt(moreFile.Filename) {
filePath = filepath.Join(filePath, "images", fileName+ext)
} else {
filePath = filepath.Join(filePath, "files", fileName+ext)
}
path := filepath.Dir(filePath) //copy the uploaded file to the destination file
dst, err := os.Create(filePath)
_ = os.MkdirAll(path, os.ModePerm) defer dst.Close()
if _, err := io.Copy(dst, file); err != nil {
err = c.SaveToFile(name, filePath) logs.Error("保存文件失败 -> ", err)
if err != nil {
logs.Error("保存文件失败 -> ", err)
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
}
attachment := models.NewAttachment()
attachment.BookId = bookId
attachment.FileName = moreFile.Filename
attachment.CreateAt = c.Member.MemberId
attachment.FileExt = ext
attachment.FilePath = strings.TrimPrefix(filePath, conf.WorkingDirectory)
attachment.DocumentId = docId
if fileInfo, err := os.Stat(filePath); err == nil {
attachment.FileSize = float64(fileInfo.Size())
}
if docId > 0 {
attachment.DocumentId = docId
}
if filetil.IsImageExt(moreFile.Filename) {
attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
if strings.HasPrefix(attachment.HttpPath, "//") {
attachment.HttpPath = conf.URLForWithCdnImage(string(attachment.HttpPath[1:]))
}
isAttach = false
}
err = attachment.Insert()
if err != nil {
os.Remove(filePath)
logs.Error("文件保存失败 ->", err)
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
}
if attachment.HttpPath == "" {
attachment.HttpPath = conf.URLForNotHost("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
if err := attachment.Update(); err != nil {
logs.Error("保存文件失败 ->", err)
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed")) c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
} }
// if err != nil {
// logs.Error("保存文件失败 -> ", err)
// c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
// }
attachment := models.NewAttachment()
attachment.BookId = bookId
// attachment.FileName = moreFile.Filename
attachment.FileName = files[i].Filename
attachment.CreateAt = c.Member.MemberId
attachment.FileExt = ext
attachment.FilePath = strings.TrimPrefix(filePath, conf.WorkingDirectory)
attachment.DocumentId = docId
if fileInfo, err := os.Stat(filePath); err == nil {
attachment.FileSize = float64(fileInfo.Size())
}
if docId > 0 {
attachment.DocumentId = docId
}
// if filetil.IsImageExt(moreFile.Filename) {
if filetil.IsImageExt(files[i].Filename) {
attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
if strings.HasPrefix(attachment.HttpPath, "//") {
attachment.HttpPath = conf.URLForWithCdnImage(string(attachment.HttpPath[1:]))
}
isAttach = false
}
err = attachment.Insert()
if err != nil {
os.Remove(filePath)
logs.Error("文件保存失败 ->", err)
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
}
if attachment.HttpPath == "" {
attachment.HttpPath = conf.URLForNotHost("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
if err := attachment.Update(); err != nil {
logs.Error("保存文件失败 ->", err)
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
}
}
result := map[string]interface{}{
"errcode": 0,
"success": 1,
"message": "ok",
"url": attachment.HttpPath,
"alt": attachment.FileName,
"is_attach": isAttach,
"attach": attachment,
}
result2 = append(result2, result)
} }
result := map[string]interface{}{ c.Ctx.Output.JSON(result2, true, false)
"errcode": 0,
"success": 1,
"message": "ok",
"url": attachment.HttpPath,
"alt": attachment.FileName,
"is_attach": isAttach,
"attach": attachment,
}
c.Ctx.Output.JSON(result, true, false)
c.StopRun() c.StopRun()
} }
@ -946,23 +1002,18 @@ func (c *DocumentController) Export() {
output := c.GetString("output") output := c.GetString("output")
token := c.GetString("token") token := c.GetString("token")
logs.Info(identify)
logs.Info(output)
logs.Info(token)
// 如果没有开启匿名访问则跳转到登录 // 如果没有开启匿名访问则跳转到登录
if !c.EnableAnonymous && !c.isUserLoggedIn() { if !c.EnableAnonymous && !c.isUserLoggedIn() {
logs.Info(output)
promptUserToLogIn(c) promptUserToLogIn(c)
return return
} }
if !conf.GetEnableExport() { if !conf.GetEnableExport() {
logs.Info(output)
c.ShowErrorPage(500, i18n.Tr(c.Lang, "export_func_disable")) c.ShowErrorPage(500, i18n.Tr(c.Lang, "export_func_disable"))
} }
bookResult := models.NewBookResult() bookResult := models.NewBookResult()
if c.Member != nil && c.Member.IsAdministrator() { if c.Member != nil && c.Member.IsAdministrator() {
logs.Info(output)
book, err := models.NewBook().FindByIdentify(identify) book, err := models.NewBook().FindByIdentify(identify)
if err != nil { if err != nil {
if err == orm.ErrNoRows { if err == orm.ErrNoRows {
@ -974,21 +1025,16 @@ func (c *DocumentController) Export() {
} }
bookResult = models.NewBookResult().ToBookResult(*book) bookResult = models.NewBookResult().ToBookResult(*book)
} else { } else {
logs.Info(output)
bookResult = c.isReadable(identify, token) bookResult = c.isReadable(identify, token)
} }
if !bookResult.IsDownload { if !bookResult.IsDownload {
logs.Info(output)
c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.cur_project_export_func_disable")) c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.cur_project_export_func_disable"))
} }
if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") { if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") {
logs.Info(output)
bookResult.Cover = conf.URLForWithCdnImage(bookResult.Cover) bookResult.Cover = conf.URLForWithCdnImage(bookResult.Cover)
} }
logs.Info(Markdown)
if output == Markdown { if output == Markdown {
logs.Info("hah")
if bookResult.Editor != EditorMarkdown && bookResult.Editor != EditorCherryMarkdown { if bookResult.Editor != EditorMarkdown && bookResult.Editor != EditorCherryMarkdown {
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.cur_project_not_support_md")) c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.cur_project_not_support_md"))
} }

View File

@ -46,149 +46,149 @@
action += "&callback=" + settings.uploadCallbackURL + "&dialog_id=editormd-image-dialog-" + guid; action += "&callback=" + settings.uploadCallbackURL + "&dialog_id=editormd-image-dialog-" + guid;
} }
var dialogContent = ( (settings.imageUpload) ? "<form action=\"" + action +"\" target=\"" + iframeName + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"" + classPrefix + "form\">" : "<div class=\"" + classPrefix + "form\">" ) + var dialogContent = ((settings.imageUpload) ? "<form action=\"" + action + "\" target=\"" + iframeName + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"" + classPrefix + "form\">" : "<div class=\"" + classPrefix + "form\">") +
( (settings.imageUpload) ? "<iframe name=\"" + iframeName + "\" id=\"" + iframeName + "\" guid=\"" + guid + "\"></iframe>" : "" ) + ((settings.imageUpload) ? "<iframe name=\"" + iframeName + "\" id=\"" + iframeName + "\" guid=\"" + guid + "\"></iframe>" : "") +
"<label>" + imageLang.url + "</label>" + "<label>" + imageLang.url + "</label>" +
"<input type=\"text\" data-url />" + (function(){ "<input type=\"text\" data-url />" + (function() {
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" + return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" />" + // 3xxx 下行添加multiple=\"multiple\"
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" + "<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" multiple=\"multiple\" />" +
"</div>" : ""; "<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
})() + "</div>" : "";
"<br/>" + })() +
"<label>" + imageLang.alt + "</label>" + "<br/>" +
"<input type=\"text\" value=\"" + selection + "\" data-alt />" + "<label>" + imageLang.alt + "</label>" +
"<br/>" + "<input type=\"text\" value=\"" + selection + "\" data-alt />" +
"<label>" + imageLang.link + "</label>" + "<br/>" +
"<input type=\"text\" value=\"http://\" data-link />" + "<label>" + imageLang.link + "</label>" +
"<br/>" + "<input type=\"text\" value=\"http://\" data-link />" +
( (settings.imageUpload) ? "</form>" : "</div>"); "<br/>" +
((settings.imageUpload) ? "</form>" : "</div>");
//var imageFooterHTML = "<button class=\"" + classPrefix + "btn " + classPrefix + "image-manager-btn\" style=\"float:left;\">" + imageLang.managerButton + "</button>"; //var imageFooterHTML = "<button class=\"" + classPrefix + "btn " + classPrefix + "image-manager-btn\" style=\"float:left;\">" + imageLang.managerButton + "</button>";
dialog = this.createDialog({
dialog = this.createDialog({ title: imageLang.title,
title : imageLang.title, width: (settings.imageUpload) ? 465 : 380,
width : (settings.imageUpload) ? 465 : 380, height: 254,
height : 254, name: dialogName,
name : dialogName, content: dialogContent,
content : dialogContent, mask: settings.dialogShowMask,
mask : settings.dialogShowMask, drag: settings.dialogDraggable,
drag : settings.dialogDraggable, lockScreen: settings.dialogLockScreen,
lockScreen : settings.dialogLockScreen, maskStyle: {
maskStyle : { opacity: settings.dialogMaskOpacity,
opacity : settings.dialogMaskOpacity, backgroundColor: settings.dialogMaskBgColor
backgroundColor : settings.dialogMaskBgColor },
}, // 这里将多图片地址改造后插入文档中
buttons : { buttons: {
enter : [lang.buttons.enter, function() { enter: [lang.buttons.enter, function() {
var url = this.find("[data-url]").val(); var url = this.find("[data-url]").val();
var alt = this.find("[data-alt]").val(); var alt = this.find("[data-alt]").val();
var link = this.find("[data-link]").val(); var link = this.find("[data-link]").val();
if (url === "") {
if (url === "") alert(imageLang.imageURLEmpty);
{ return false;
alert(imageLang.imageURLEmpty); }
return false; // 这里增加循环
} let arr = url.split(";");
var altAttr = (alt !== "") ? " \"" + alt + "\"" : "";
var altAttr = (alt !== "") ? " \"" + alt + "\"" : ""; for (let i = 0; i < arr.length; i++) {
if (link === "" || link === "http://") {
if (link === "" || link === "http://") // cm.replaceSelection("![" + alt + "](" + url + altAttr + ")");
{ cm.replaceSelection("![" + alt + "](" + arr[i] + altAttr + ")");
cm.replaceSelection("![" + alt + "](" + url + altAttr + ")"); } else {
} // cm.replaceSelection("[![" + alt + "](" + url + altAttr + ")](" + link + altAttr + ")");
else cm.replaceSelection("[![" + alt + "](" + arr[i] + altAttr + ")](" + link + altAttr + ")");
{
cm.replaceSelection("[![" + alt + "](" + url + altAttr + ")](" + link + altAttr + ")");
}
if (alt === "") {
cm.setCursor(cursor.line, cursor.ch + 2);
}
this.hide().lockScreen(false).hideMask();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
return false;
}]
}
});
dialog.attr("id", classPrefix + "image-dialog-" + guid);
if (!settings.imageUpload) {
return ;
} }
}
if (alt === "") {
cm.setCursor(cursor.line, cursor.ch + 2);
}
this.hide().lockScreen(false).hideMask();
return false;
}],
var fileInput = dialog.find("[name=\"" + classPrefix + "image-file\"]"); cancel: [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
fileInput.bind("change", function() { return false;
var fileName = fileInput.val(); }]
var isImage = new RegExp("(\\.(" + settings.imageFormats.join("|") + "))$"); // /(\.(webp|jpg|jpeg|gif|bmp|png))$/ }
});
if (fileName === "") dialog.attr("id", classPrefix + "image-dialog-" + guid);
{ if (!settings.imageUpload) {
alert(imageLang.uploadFileEmpty); return;
}
return false; var fileInput = dialog.find("[name=\"" + classPrefix + "image-file\"]");
} fileInput.bind("change", function() {
// 3xxx 20240602
if (!isImage.test(fileName)) // let formData = new FormData();
{ // 获取文本框dom
alert(imageLang.formatNotAllowed + settings.imageFormats.join(", ")); // var doc = document.getElementById('doc');
// 获取上传控件dom
return false; // var upload = document.getElementById('upload');
} // let files = upload.files;
//遍历文件信息append到formData存储
loading(true); // for (let i = 0; i < files.length; i++) {
// let file = files[i]
var submitHandler = function() { // formData.append('files', file)
// }
var uploadIframe = document.getElementById(iframeName); // 获取文件名
// var fileName = upload.files[0].name;
uploadIframe.onload = function() { // 获取文件路径
// var filePath = upload.value;
loading(false); // doc.value = fileName;
// 3xxx
var body = (uploadIframe.contentWindow ? uploadIframe.contentWindow : uploadIframe.contentDocument).document.body; console.log(fileInput);
var json = (body.innerText) ? body.innerText : ( (body.textContent) ? body.textContent : null); console.log(fileInput[0].files);
let files = fileInput[0].files;
json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")"); for (let i = 0; i < files.length; i++) {
var fileName = files[i].name;
if (json.success === 1) // var fileName = fileInput.val();
{ var isImage = new RegExp("(\\.(" + settings.imageFormats.join("|") + "))$"); // /(\.(webp|jpg|jpeg|gif|bmp|png))$/
dialog.find("[data-url]").val(json.url); if (fileName === "") {
} alert(imageLang.uploadFileEmpty);
else return false;
{
alert(json.message);
}
return false;
};
};
dialog.find("[type=\"submit\"]").bind("click", submitHandler).trigger("click");
});
} }
if (!isImage.test(fileName)) {
dialog = editor.find("." + dialogName); alert(imageLang.formatNotAllowed + settings.imageFormats.join(", "));
dialog.find("[type=\"text\"]").val(""); return false;
dialog.find("[type=\"file\"]").val(""); }
dialog.find("[data-link]").val("http://"); loading(true);
var submitHandler = function() {
this.dialogShowMask(dialog); var uploadIframe = document.getElementById(iframeName);
this.dialogLockScreen(); uploadIframe.onload = function() {
dialog.show(); loading(false);
var body = (uploadIframe.contentWindow ? uploadIframe.contentWindow : uploadIframe.contentDocument).document.body;
}; var json = (body.innerText) ? body.innerText : ((body.textContent) ? body.textContent : null);
json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
}; var url="";
for (let i = 0; i < json.length; i++) {
if (json[i].success === 1) {
if (i==0){
url=json[i].url;
}else{
url=url+";"+json[i].url;
}
} else {
alert(json[i].message);
}
}
dialog.find("[data-url]").val(url)
return false;
};
};
dialog.find("[type=\"submit\"]").bind("click", submitHandler).trigger("click");
}
});
}
dialog = editor.find("." + dialogName);
dialog.find("[type=\"text\"]").val("");
dialog.find("[type=\"file\"]").val("");
dialog.find("[data-link]").val("http://");
this.dialogShowMask(dialog);
this.dialogLockScreen();
dialog.show();
};
};
// CommonJS/Node.js // CommonJS/Node.js
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") if (typeof require === "function" && typeof exports === "object" && typeof module === "object")

View File

@ -53,8 +53,10 @@ $(function () {
shade: [0.1, '#fff'] // 0.1 透明度的白色背景 shade: [0.1, '#fff'] // 0.1 透明度的白色背景
}); });
} else if ($state === "success") { } else if ($state === "success") {
if ($res.errcode === 0) { // if ($res.errcode === 0) {
var value = '![](' + $res.url + ')'; // var value = '![](' + $res.url + ')';
if ($res[0].errcode === 0) {
var value = '![](' + $res[0].url + ')';
window.editor.insertValue(value); window.editor.insertValue(value);
} }
} }

View File

@ -251,8 +251,11 @@ $(function () {
shade: [0.1, '#fff'] // 0.1 透明度的白色背景 shade: [0.1, '#fff'] // 0.1 透明度的白色背景
}); });
} else if ($state === "success") { } else if ($state === "success") {
if ($res.errcode === 0) { // if ($res.errcode === 0) {
var value = '![](' + $res.url + ')'; // var value = '![](' + $res.url + ')';
// 3xxx 20240602
if ($res[0].errcode === 0) {
var value = '![](' + $res[0].url + ')';
window.editor.insertValue(value); window.editor.insertValue(value);
} }
} }

View File

@ -77,10 +77,11 @@ $(function () {
shade: [0.1, '#fff'] // 0.1 透明度的白色背景 shade: [0.1, '#fff'] // 0.1 透明度的白色背景
}); });
} else if ($state === "success") { } else if ($state === "success") {
if ($res.errcode === 0) { // if ($res.errcode === 0) {
if ($res[0].errcode === 0) {
var range = window.editor.getSelection(); var range = window.editor.getSelection();
window.editor.insertEmbed(range.index, 'image', $res.url); // window.editor.insertEmbed(range.index, 'image', $res.url);
window.editor.insertEmbed(range.index, 'image', $res[0].url);
} }
} }
}); });