Commit 3bb51597 authored by Medicean's avatar Medicean

上传文件分片大小可自定义设置,默认为500kb

parent a68c74d1
...@@ -122,7 +122,11 @@ class Request { ...@@ -122,7 +122,11 @@ class Request {
}, res, callback); }, res, callback);
}) })
.end((err, ret) => { .end((err, ret) => {
let buff = ret.body; if (!ret) {
// 请求失败 TIMEOUT
return event.sender.send('request-error-' + opts['hash'], err);
}
let buff = ret.hasOwnProperty('body') ? ret.body : new Buffer();
// 解码 // 解码
let text = iconv.decode(buff, opts['encode']); let text = iconv.decode(buff, opts['encode']);
if (err && text == "") { if (err && text == "") {
......
...@@ -170,6 +170,7 @@ module.exports = { ...@@ -170,6 +170,7 @@ module.exports = {
nohttps: 'Ignore HTTPS certificate', nohttps: 'Ignore HTTPS certificate',
terminalCache: "Use the terminal's cache", terminalCache: "Use the terminal's cache",
filemanagerCache: "Use the filemanager's cache", filemanagerCache: "Use the filemanager's cache",
uploadFragment: "Upload File Fragmentation Size",
requestTimeout: 'Request timeout', requestTimeout: 'Request timeout',
commandPath: 'Custom terminal-execPath' commandPath: 'Custom terminal-execPath'
} }
...@@ -240,6 +241,9 @@ module.exports = { ...@@ -240,6 +241,9 @@ module.exports = {
task: { task: {
name: 'Upload', name: 'Upload',
success: 'Upload success!', success: 'Upload success!',
httperr_413: 'Please lower the upload file shard size setting.',
httperr_etime: 'Request timeout, please increase the timeout period.',
httperr_econnrefused: 'Connection refused, check target or proxy is enabled.',
failed: (err) => antSword.noxss(`Failed:${err}`), failed: (err) => antSword.noxss(`Failed:${err}`),
error: (err) => antSword.noxss(`Error:${err}`) error: (err) => antSword.noxss(`Error:${err}`)
}, },
......
...@@ -171,6 +171,7 @@ module.exports = { ...@@ -171,6 +171,7 @@ module.exports = {
nohttps: '忽略HTTPS证书', nohttps: '忽略HTTPS证书',
terminalCache: '虚拟终端使用缓存', terminalCache: '虚拟终端使用缓存',
filemanagerCache: '文件管理使用缓存', filemanagerCache: '文件管理使用缓存',
uploadFragment: '上传文件分片大小',
requestTimeout: '请求超时', requestTimeout: '请求超时',
commandPath: '自定义终端执行路径' commandPath: '自定义终端执行路径'
} }
...@@ -241,6 +242,9 @@ module.exports = { ...@@ -241,6 +242,9 @@ module.exports = {
task: { task: {
name: '上传', name: '上传',
success: '上传成功', success: '上传成功',
httperr_413: '请将上传文件分片大小设置调低',
httperr_etime: '请求超时,请将超时时间调大',
httperr_econnrefused: '连接被拒绝,检查目标或代理是否开启',
failed: (err) => antSword.noxss(`失败:${err}`), failed: (err) => antSword.noxss(`失败:${err}`),
error: (err) => antSword.noxss(`出错:${err}`) error: (err) => antSword.noxss(`出错:${err}`)
}, },
......
...@@ -696,9 +696,9 @@ class FileManager { ...@@ -696,9 +696,9 @@ class FileManager {
let buffIndex = 0; let buffIndex = 0;
let buff = []; let buff = [];
// 分段上传大小,默认0.5M(jsp 超过1M响应会出错) // 分段上传大小,默认0.5M(jsp 超过1M响应会出错)
let dataSplit = 512 * 1024; let dataSplit = 500 * 1024;
if (this.opts['type'].toLowerCase() === 'php') { if ( parseInt((this.opts.otherConf || {})['upload-fragment']) > 0 ) {
dataSplit = 1024 * 1024 dataSplit = parseInt((this.opts.otherConf || {})['upload-fragment']) * 1024;
} }
let task = tasks[filePath]; let task = tasks[filePath];
// 获取文件名 // 获取文件名
...@@ -751,8 +751,32 @@ class FileManager { ...@@ -751,8 +751,32 @@ class FileManager {
ret === '0' ? '' : `<br/>${ret}` ret === '0' ? '' : `<br/>${ret}`
), LANG_T['error']); ), LANG_T['error']);
}).catch((err) => { }).catch((err) => {
task.failed(LANG['upload']['task']['error'](err)); // 出错后友好提示
toastr.error(LANG['upload']['error'](fileName, err), LANG_T['error']); let errmsg = err;
if (err.hasOwnProperty('status') && err.hasOwnProperty('response')) {
errmsg = `${err.status} ${err.response.res.statusMessage}`;
switch(err.status) {
case 413:
errmsg += `${LANG['upload']['task']['httperr_413']}`;
break;
default:
break;
}
}else if(err.hasOwnProperty('errno')) {
switch(err.errno) {
case 'ETIME':
errmsg = `${LANG['upload']['task']['httperr_etime']}`;
break;
case 'ECONNREFUSED':
errmsg = `${LANG['upload']['task']['httperr_econnrefused']}`;
break;
default:
errmsg = `${err.errno} ${err.code}`;
break;
}
}
task.failed(LANG['upload']['task']['error'](errmsg));
toastr.error(LANG['upload']['error'](fileName, errmsg), LANG_T['error']);
}); });
}) })
} }
......
...@@ -278,6 +278,7 @@ class Form { ...@@ -278,6 +278,7 @@ class Form {
'ignore-https': 0, 'ignore-https': 0,
'terminal-cache': 0, 'terminal-cache': 0,
'filemanager-cache': 1, 'filemanager-cache': 1,
'upload-fragment': '500',
'request-timeout': '10000', 'request-timeout': '10000',
'command-path': '' 'command-path': ''
}, arg.otherConf); }, arg.otherConf);
...@@ -294,7 +295,28 @@ class Form { ...@@ -294,7 +295,28 @@ class Form {
}, { }, {
type: "checkbox", name: 'filemanager-cache', label: LANG['list']['otherConf']['filemanagerCache'], type: "checkbox", name: 'filemanager-cache', label: LANG['list']['otherConf']['filemanagerCache'],
checked: opt['filemanager-cache'] === 1 checked: opt['filemanager-cache'] === 1
},{ }, {
type: "label", label: LANG['list']['otherConf']['uploadFragment']
}, {
type: "combo", label: '/kb', inputWidth: 100, name: "upload-fragment",
options: ((items) => {
let ret = [];
// 如果自定义的路径不在items里,则++
if (items.indexOf(opt['upload-fragment']) === -1) {
items.unshift(opt['upload-fragment']);
}
items.map((_) => {
ret.push({
text: _,
value: _,
selected: opt['upload-fragment'] === _
})
});
return ret;
})([
'500', '400', '200', '100', '50', '10'
])
}, {
type: "label", label: LANG['list']['otherConf']['requestTimeout'] type: "label", label: LANG['list']['otherConf']['requestTimeout']
}, { }, {
type: "combo", label: '/ms', inputWidth: 100, name: "request-timeout", type: "combo", label: '/ms', inputWidth: 100, name: "request-timeout",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment