Commit 3bb51597 authored by Medicean's avatar Medicean

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

parent a68c74d1
......@@ -122,7 +122,11 @@ class Request {
}, res, callback);
})
.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']);
if (err && text == "") {
......
......@@ -170,6 +170,7 @@ module.exports = {
nohttps: 'Ignore HTTPS certificate',
terminalCache: "Use the terminal's cache",
filemanagerCache: "Use the filemanager's cache",
uploadFragment: "Upload File Fragmentation Size",
requestTimeout: 'Request timeout',
commandPath: 'Custom terminal-execPath'
}
......@@ -240,6 +241,9 @@ module.exports = {
task: {
name: 'Upload',
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}`),
error: (err) => antSword.noxss(`Error:${err}`)
},
......
......@@ -171,6 +171,7 @@ module.exports = {
nohttps: '忽略HTTPS证书',
terminalCache: '虚拟终端使用缓存',
filemanagerCache: '文件管理使用缓存',
uploadFragment: '上传文件分片大小',
requestTimeout: '请求超时',
commandPath: '自定义终端执行路径'
}
......@@ -241,6 +242,9 @@ module.exports = {
task: {
name: '上传',
success: '上传成功',
httperr_413: '请将上传文件分片大小设置调低',
httperr_etime: '请求超时,请将超时时间调大',
httperr_econnrefused: '连接被拒绝,检查目标或代理是否开启',
failed: (err) => antSword.noxss(`失败:${err}`),
error: (err) => antSword.noxss(`出错:${err}`)
},
......
......@@ -696,9 +696,9 @@ class FileManager {
let buffIndex = 0;
let buff = [];
// 分段上传大小,默认0.5M(jsp 超过1M响应会出错)
let dataSplit = 512 * 1024;
if (this.opts['type'].toLowerCase() === 'php') {
dataSplit = 1024 * 1024
let dataSplit = 500 * 1024;
if ( parseInt((this.opts.otherConf || {})['upload-fragment']) > 0 ) {
dataSplit = parseInt((this.opts.otherConf || {})['upload-fragment']) * 1024;
}
let task = tasks[filePath];
// 获取文件名
......@@ -751,8 +751,32 @@ class FileManager {
ret === '0' ? '' : `<br/>${ret}`
), LANG_T['error']);
}).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 {
'ignore-https': 0,
'terminal-cache': 0,
'filemanager-cache': 1,
'upload-fragment': '500',
'request-timeout': '10000',
'command-path': ''
}, arg.otherConf);
......@@ -294,7 +295,28 @@ class Form {
}, {
type: "checkbox", name: 'filemanager-cache', label: LANG['list']['otherConf']['filemanagerCache'],
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: "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