Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
feat(upload): amend upload service
Browse files Browse the repository at this point in the history
  • Loading branch information
Tian-Hun committed Oct 11, 2018
1 parent 43ef29d commit 8571761
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Ueditor 文档:[http://fex.baidu.com/ueditor/](http://fex.baidu.com/ueditor/)

## 联系我们 ##

Neditor官方交流群:257753500

QQ 群: 321735506

[issue](http://github.com/notadd/neditor/issues)
Expand Down
24 changes: 20 additions & 4 deletions dialogs/attachment/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
actionUrl = editor.getActionUrl(editor.getOpt('fileActionName')),
fileMaxSize = editor.getOpt('fileMaxSize'),
acceptExtensions = (editor.getOpt('fileAllowFiles') ||
[".txt",".doc",".docs",".xls",".xlsx",".ppt",".odt",".ott",".fodt",".uot",".xml",".dot",".htm",".html",".rtf",".docm",".zip",".rar",".tar",".7z",".tar.gz",".tar.bz",".tar.xz"]).join('').replace(/\./g, ',').replace(/^[,]/, '');;
console.log(acceptExtensions);
[".txt",".doc",".docs",".xls",".xlsx",".ppt",".pdf",".odt",".ott",".fodt",".uot",".xml",".dot",".htm",".html",".rtf",".docm",".zip",".rar",".tar",".7z",".tar.gz",".tar.bz",".tar.xz"]).join('').replace(/\./g, ',').replace(/^[,]/, '');;
if (!WebUploader.Uploader.support()) {
$('#filePickerReady').after($('<div>').html(lang.errorNotSupport)).hide();
return;
Expand Down Expand Up @@ -555,10 +554,27 @@
getInsertList: function () {
var i, link, data, list = [],
prefix = editor.getOpt('fileUrlPrefix'),
fileSrcField = editor.getOpt("fileUploadService")(this, editor).fileSrcField || 'url';;
fileSrcField = editor.getOpt("fileUploadService")(this, editor).fileSrcField || 'url',
fileSrc = '',
fileSrcFieldKeys = fileSrcField.split('.');

for (i = 0; i < this.fileList.length; i++) {
data = this.fileList[i];
link = data[fileSrcField];
if(fileSrcFieldKeys.length > 1) {
function setFileSrc(obj, keys, index) {
obj = obj[keys[index]];
if (index < keys.length - 1) {
setFileSrc(obj, keys, index += 1)
} else {
fileSrc = obj;
}
}

setFileSrc(data, fileSrcFieldKeys, 0);
} else {
fileSrc = data[fileSrcField];
}
link = fileSrc;
list.push({
title: data.original || link.substr(link.lastIndexOf('/') + 1),
url: prefix + link
Expand Down
25 changes: 22 additions & 3 deletions dialogs/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,31 @@
var i, data, list = [],
align = getAlign(),
prefix = editor.getOpt('imageUrlPrefix'),
imageSrcField = editor.getOpt("imageUploadService")(this, editor).imageSrcField || 'url';
imageSrcField = editor.getOpt("imageUploadService")(this, editor).imageSrcField || 'url',
imageSrc = '',
imageSrcFieldKeys = imageSrcField.split('.');

for (i = 0; i < this.imageList.length; i++) {
data = this.imageList[i];

if(imageSrcFieldKeys.length > 1) {
function setImageSrc(obj, keys, index) {
obj = obj[keys[index]];
if (index < keys.length - 1) {
setImageSrc(obj, keys, index += 1)
} else {
imageSrc = obj;
}
}

setImageSrc(data, imageSrcFieldKeys, 0);
} else {
imageSrc = data[imageSrcField];
}

list.push({
src: prefix + data[imageSrcField],
_src: prefix + data[imageSrcField],
src: prefix + imageSrc,
_src: prefix + imageSrc,
alt: data.original,
floatStyle: align
});
Expand Down
24 changes: 21 additions & 3 deletions dialogs/scrawl/scrawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,27 @@ function exec(scrawlObj) {
if (!scrawlObj.isCancelScrawl) {
if (data.responseSuccess) {
var imgObj = {},
url = editor.options.scrawlUrlPrefix + data[data.scrawlSrcField];
imgObj.src = url;
imgObj._src = url;
srcField = data.scrawlSrcField || 'url',
src = '',
srcFieldKeys = srcField.split('.'),
prefix = editor.options.scrawlUrlPrefix;

if(srcFieldKeys.length > 1) {
function setSrc(obj, keys, index) {
obj = obj[keys[index]];
if (index < keys.length - 1) {
setSrc(obj, keys, index += 1)
} else {
src = obj;
}
}
setSrc(data, srcFieldKeys, 0);
} else {
src = data[srcField];
}

imgObj.src = prefix + src;
imgObj._src = prefix + src;
imgObj.alt = data.original || '';
editor.execCommand("insertImage", imgObj);
dialog.close();
Expand Down
22 changes: 20 additions & 2 deletions dialogs/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,29 @@
height = $G('upload_height').value || 280,
align = findFocus("upload_alignment","name") || 'none',
videoSrcField = editor.getOpt("videoUploadService")(this, editor).videoSrcField || 'url';
videoSrc = '',
videoSrcFieldKeys = videoSrcField.split('.');

for(var key in uploadVideoList) {
var file = uploadVideoList[key];

if(videoSrcFieldKeys.length > 1) {
function setVideoSrc(obj, keys, index) {
obj = obj[keys[index]];
if (index < keys.length - 1) {
setVideoSrc(obj, keys, index += 1)
} else {
videoSrc = obj;
}
}

setVideoSrc(file, videoSrcFieldKeys, 0);
} else {
videoSrc = file[videoSrcField];
}

videoObjs.push({
url: prefix + file[videoSrcField],
url: prefix + videoSrc,
width:width,
height:height,
align:align
Expand Down Expand Up @@ -711,7 +730,6 @@
break;
case 'startUpload':
/* 设置Uploader配置项 */
console.log(uploader)
editor.getOpt("videoUploadService")(_this, editor).setUploaderOptions(uploader);
setState('uploading', files);
break;
Expand Down
45 changes: 39 additions & 6 deletions neditor.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ window.UEDITOR_CONFIG['imageUploadService'] = function(context, editor) {
},
/**
* 触发uploadSuccess事件时执行
* 当文件上传成功时触发
* 当文件上传成功时触发,可以在这里修改上传接口返回的response对象
* @param {Object} res 上传接口返回的response
* @returns {Boolean} 上传接口返回的response成功状态条件 (比如: res.code == 200)
*/
getResponseSuccess: function(res) {
return res.code == 200;
},
/* 指定上传接口返回的response中图片路径的字段,默认为 url */
/* 指定上传接口返回的response中图片路径的字段,默认为 url
* 如果图片路径字段不是res的属性,可以写成 对象.属性 的方式,例如:data.url
* */
imageSrcField: 'url'
}
};
Expand Down Expand Up @@ -104,14 +106,16 @@ window.UEDITOR_CONFIG['videoUploadService'] = function(context, editor) {
},
/**
* 触发uploadSuccess事件时执行
* 当文件上传成功时触发
* 当文件上传成功时触发,可以在这里修改上传接口返回的response对象
* @param {Object} res 上传接口返回的response
* @returns {Boolean} 上传接口返回的response成功状态条件 (比如: res.code == 200)
*/
getResponseSuccess: function(res) {
return res.code == 200;
},
/* 指定上传接口返回的response中视频路径的字段,默认为 url */
/* 指定上传接口返回的response中视频路径的字段,默认为 url
* 如果视频路径字段不是res的属性,可以写成 对象.属性 的方式,例如:data.url
* */
videoSrcField: 'url'
}
};
Expand All @@ -132,6 +136,7 @@ window.UEDITOR_CONFIG['scrawlUploadService'] = function(context, editor) {
* @param {Function} success 上传成功回调函数,回传上传成功的response对象
* @param {Function} fail 上传失败回调函数,回传上传失败的response对象
*/

/**
* 上传成功的response对象必须为以下两个属性赋值
*
Expand All @@ -142,6 +147,32 @@ window.UEDITOR_CONFIG['scrawlUploadService'] = function(context, editor) {
* res.videoSrcField = 'url';
*/
uploadScraw: function(file, base64, success, fail) {

/* 模拟上传操作 */
var formData = new FormData();
formData.append('file', file, file.name);

$.ajax({
url: editor.getActionUrl(editor.getOpt('scrawlActionName')),
type: 'POST',
data: formData
}).done(function(res) {
var res = JSON.parse(res);

/* 上传接口返回的response成功状态条件 (比如: res.code == 200) */
res.responseSuccess = res.code == 200;

/* 指定上传接口返回的response中涂鸦图片路径的字段,默认为 url
* 如果涂鸦图片路径字段不是res的属性,可以写成 对象.属性 的方式,例如:data.url
*/
res.scrawlSrcField = 'url';

/* 上传成功 */
success.call(context, res);
}).fail(function(err) {
/* 上传失败 */
fail.call(context, err);
});
}
}
}
Expand Down Expand Up @@ -184,14 +215,16 @@ window.UEDITOR_CONFIG['fileUploadService'] = function(context, editor) {
},
/**
* 触发uploadSuccess事件时执行
* 当文件上传成功时触发
* 当文件上传成功时触发,可以在这里修改上传接口返回的response对象
* @param {Object} res 上传接口返回的response
* @returns {Boolean} 上传接口返回的response成功状态条件 (比如: res.code == 200)
*/
getResponseSuccess: function(res) {
return res.code == 200;
},
/* 指定上传接口返回的response中附件路径的字段,默认为 url */
/* 指定上传接口返回的response中附件路径的字段,默认为 url
* 如果附件路径字段不是res的属性,可以写成 对象.属性 的方式,例如:data.url
* */
fileSrcField: 'url'
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@notadd/neditor",
"title": "neditor",
"description": "Neditor富文本web编辑器",
"version": "2.1.5",
"version": "2.1.6",
"homepage": "https://github.com/notadd/neditor",
"author": {
"name": "Notadd",
Expand Down

0 comments on commit 8571761

Please sign in to comment.