v1.2.1版本,优化调整了很多,整改验收阶段新加字段
This commit is contained in:
42
main.js
42
main.js
@@ -36,24 +36,36 @@ uni.addInterceptor('chooseImage', {
|
||||
}
|
||||
});
|
||||
|
||||
// 全局拦截文件上传,校验文件后缀是否在后端白名单中,预防非法格式报错
|
||||
// 全局拦截文件上传:校验本地文件后缀;七牛直传按 upload 域名放行
|
||||
const UPLOAD_ALLOWED_EXTENSIONS = ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'html', 'htm', 'txt', 'rar', 'zip', 'gz', 'bz2', 'mp4', 'avi', 'rmvb', 'pdf'];
|
||||
const QINIU_UPLOAD_HOST_MARKERS = ['qiniup.com', 'qbox.me'];
|
||||
|
||||
function validateUploadLocalFileExt(filePath) {
|
||||
if (!filePath) return true;
|
||||
const cleanPath = filePath.split('?')[0];
|
||||
const ext = cleanPath.split('.').pop().toLowerCase();
|
||||
if (!UPLOAD_ALLOWED_EXTENSIONS.includes(ext)) {
|
||||
uni.showToast({
|
||||
title: `不支持 .${ext} 格式,请上传合规的文件或图片`,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uni.addInterceptor('uploadFile', {
|
||||
invoke(args) {
|
||||
const filePath = args.filePath;
|
||||
if (filePath) {
|
||||
const cleanPath = filePath.split('?')[0];
|
||||
const ext = cleanPath.split('.').pop().toLowerCase();
|
||||
const allowedExtensions = ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'html', 'htm', 'txt', 'rar', 'zip', 'gz', 'bz2', 'mp4', 'avi', 'rmvb', 'pdf'];
|
||||
if (!allowedExtensions.includes(ext)) {
|
||||
uni.showToast({
|
||||
title: `不支持 .${ext} 格式,请上传合规的文件或图片`,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
return false; // 拦截请求
|
||||
}
|
||||
const uploadUrl = args.url || '';
|
||||
const isQiniuUpload = QINIU_UPLOAD_HOST_MARKERS.some((m) => uploadUrl.includes(m));
|
||||
if (isQiniuUpload) {
|
||||
return validateUploadLocalFileExt(args.filePath) ? args : false;
|
||||
}
|
||||
return args;
|
||||
if (uploadUrl.includes('/frontend/attachment/upload')) {
|
||||
return validateUploadLocalFileExt(args.filePath) ? args : false;
|
||||
}
|
||||
return validateUploadLocalFileExt(args.filePath) ? args : false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user