Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
ezijing-node-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
ezijing-node-server
Commits
4bf13e56
提交
4bf13e56
authored
7月 22, 2020
作者:
zyx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加 图片上传接口
上级
73132fb9
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
45 行删除
+23
-45
CkeditorMonitor.js
server/controller/CkeditorMonitor.js
+21
-43
index.js
server/routes/index.js
+2
-2
没有找到文件。
server/controller/CkeditorMonitor.js
浏览文件 @
4bf13e56
...
...
@@ -3,10 +3,7 @@ const fs = require('fs')
const
conf
=
require
(
'../config'
)
const
com
=
require
(
'@god/node-com'
)
const
axios
=
require
(
'axios'
)
/* 支持 finally函数 */
require
(
'promise.prototype.finally'
).
shim
()
const
Proxy
=
com
.
Proxy
const
ckeditorUpload
=
(
req
,
res
)
=>
{
/* 文件上传 ckeditor4.5以上返回格式 */
...
...
@@ -23,50 +20,31 @@ const ckeditorUpload = (req, res) => {
if
(
req
.
files
.
length
)
{
if
(
!
req
.
files
[
0
].
mimetype
.
startsWith
(
'image'
))
{
sendHtml
(
''
,
'文件类型错误,请上传图片'
);
return
}
if
(
req
.
files
[
0
].
size
>
10
*
1024
*
1024
)
{
sendHtml
(
''
,
'图片大小超限'
);
return
}
req
.
files
[
0
].
fieldname
=
'image'
let
headers
=
req
.
headers
let
options
=
{}
options
=
{
timeout
:
30
*
1000
,
url
:
'util/upload-image'
,
baseURL
:
conf
.
agentApiUrl
,
method
:
req
.
method
,
data
:
req
.
body
,
params
:
req
.
query
req
.
files
[
0
].
fieldname
=
'file'
Proxy
.
reqHttps
({
hostname
:
req
.
host
,
path
:
'/api/lms/util/upload-file'
,
method
:
'POST'
,
data
:
req
.
body
||
{},
query
:
req
.
query
||
{},
files
:
req
.
files
,
headers
:
{
'tenant'
:
req
.
headers
.
tenant
,
'Cookie'
:
req
.
headers
.
cookie
||
''
,
'User-Agent'
:
req
.
headers
[
'user-agent'
],
'Content-Type'
:
'multipart/form-data'
}
headers
[
'accept'
]
=
'*/*'
delete
headers
[
'accept-language'
]
let
_fileName
=
com
.
Tool
.
ReqType
.
toFormData
(
req
,
options
)
headers
[
'token'
]
=
com
.
Tool
.
Cookie
.
getTicketByCAS
(
'_SUP'
,
req
)
headers
[
'tenant'
]
=
'classes'
headers
[
'apikey'
]
=
'ITol9gsbkEb85gnaxIu7oWfHDOaKgwbH'
headers
[
'Host'
]
=
'ep-api.ezijing.com'
headers
[
'host'
]
=
'ep-api.ezijing.com'
axios
.
defaults
.
headers
=
headers
/* 重新转发请求 */
axios
(
options
).
then
((
data
)
=>
{
if
(
data
.
data
.
success
)
{
sendHtml
(
data
.
data
.
url
,
''
)
},
function
(
str
,
obj
)
{
try
{
const
_json
=
JSON
.
parse
(
str
)
if
(
_json
.
success
)
{
sendHtml
(
_json
.
url
,
''
)
}
else
{
sendHtml
(
''
,
'上传错误,请重试'
)
}
req
.
files
.
forEach
((
elem
,
i
)
=>
{
fs
.
stat
(
elem
.
destination
+
elem
.
originalname
,
(
error
,
stats
)
=>
{
if
(
error
)
{
return
}
fs
.
unlink
(
elem
.
destination
+
elem
.
originalname
,
(
error
)
=>
{
if
(
error
)
console
.
log
(
error
)
})
})
})
}).
catch
((
e
)
=>
{
}
catch
(
e
)
{
sendHtml
(
''
,
'上传错误,请重试1'
)
}).
finally
(()
=>
{
/* 请求结束,删除服务器端 缓存文件 */
if
(
_fileName
.
length
)
{
for
(
let
i
=
0
;
i
<
_fileName
.
length
;
i
++
)
{
fs
.
unlinkSync
(
_fileName
[
i
])
}
}
})
}
...
...
server/routes/index.js
浏览文件 @
4bf13e56
...
...
@@ -13,7 +13,7 @@ const _sccm = require('../controller/setCloudClassMonitor')
const
_nts
=
require
(
'../controller/NextToSend'
)
const
_pr
=
require
(
'../controller/ProxyRequest'
)
const
_wxcsm
=
require
(
'../controller/wxChartSuccessMonitor'
)
//
const _cm = require('../controller/CkeditorMonitor')
const
_cm
=
require
(
'../controller/CkeditorMonitor'
)
router
.
use
(
bodyParser
.
json
({
limit
:
'60mb'
}))
router
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
,
limit
:
'60mb'
}))
...
...
@@ -65,7 +65,7 @@ router.use('/v1/pay/wechat/*', _pr.use)
router
.
use
(
'/get/wx-chart/*'
,
_wxcsm
.
get
)
router
.
use
(
'/set/wx-chart/*'
,
_wxcsm
.
set
)
// 支持 ckeditor 图片上传
//
router.use('/form/ckeditor-upload', upload.any(), _cm.ckeditorUpload)
router
.
use
(
'/form/ckeditor-upload'
,
upload
.
any
(),
_cm
.
ckeditorUpload
)
router
.
use
(
'/api/*'
,
upload
.
any
(),
(
req
,
res
)
=>
{
res
.
send
(
'暂无该接口'
)
})
router
.
use
(
'*'
,
upload
.
any
(),
(
req
,
res
)
=>
{
res
.
send
(
'接口未定义'
)
})
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论