Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "fhcommon", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "泛华前端的上传方法", | ||
@@ -5,0 +5,0 @@ "main": "dist/fhcommon.min.js", |
@@ -8,7 +8,7 @@ | ||
} | ||
if (!window.AWS) { | ||
loadJavaScript('https://dop-pro-1251973116.file.myqcloud.com/upload/jsfile/funzg/aws-sdk-2.1562.0.min.js', () => { | ||
console.log('aws-sdk 加载成功'); | ||
}); | ||
} | ||
// if (!window.AWS) { | ||
// loadJavaScript('https://dop-pro-1251973116.file.myqcloud.com/upload/jsfile/funzg/aws-sdk-2.1562.0.min.js', () => { | ||
// console.log('aws-sdk 加载成功'); | ||
// }); | ||
// } | ||
if (!window.COS) { | ||
@@ -78,3 +78,3 @@ loadJavaScript('https://dop-pro-1251973116.file.myqcloud.com/upload/jsfile/funzg/cos-js-sdk-v5.min.js', () => { | ||
return axios.get(`/funapi/config/oss/sign/${target}/${project}`).then(res => { | ||
if (target !== '2') res = JSON.parse(FHENCYPT.decrypt(res.data || res)) | ||
if (target !== '2' && (typeof res.data === 'string' || typeof res === 'string')) res = JSON.parse(FHENCYPT.decrypt(res.data || res)) | ||
const { tmpSecretId, tmpSecretKey, token, sessionToken, startTime, expiredTime, requestId, type, bucketName, region, cdnUrl } = res.data || res; | ||
@@ -91,41 +91,42 @@ /** | ||
*/ | ||
if (type === '1') { // 亚马逊 | ||
AWS.config.update({ | ||
accessKeyId: tmpSecretId, | ||
secretAccessKey: tmpSecretKey, | ||
region: region, | ||
sessionToken: token | ||
}); | ||
const s3 = new AWS.S3(); | ||
const params = { | ||
Bucket: bucketName, | ||
Key: newKey, | ||
ContentType: type, | ||
Body: file, | ||
'Access-Control-Allow-Credentials': '*' | ||
}; | ||
const upload = s3.upload(params); | ||
upload.on('httpUploadProgress', (progress) => { | ||
const { loaded, total } = progress; | ||
/* 非必须 */ | ||
const percent = Math.round(parseInt(loaded / total) * 100); | ||
if (typeof onProgress === 'function') onProgress(percent); | ||
}); | ||
const uploadPromise = upload.promise(); | ||
return uploadPromise.then(res => { | ||
const { key, Key } = res; | ||
console.log(res); | ||
// const tempUrl = (key.startsWith('/') ? '' : '/'); | ||
const fileUrl = `${cdnUrl}${cdnUrl.endsWith('/') ? '' : '/'}${key || Key}` | ||
if (needWholeRes) { | ||
return { | ||
...res, | ||
fileUrl | ||
}; | ||
} return fileUrl; | ||
}).catch(err => { | ||
console.log(err); | ||
}).finally(_ => { | ||
}); | ||
} else if (type === '2') { // 如果type=2 则使用minIO上传 | ||
// if (type === '1') { // 亚马逊 | ||
// AWS.config.update({ | ||
// accessKeyId: tmpSecretId, | ||
// secretAccessKey: tmpSecretKey, | ||
// region: region, | ||
// sessionToken: token | ||
// }); | ||
// const s3 = new AWS.S3(); | ||
// const params = { | ||
// Bucket: bucketName, | ||
// Key: newKey, | ||
// ContentType: type, | ||
// Body: file, | ||
// 'Access-Control-Allow-Credentials': '*' | ||
// }; | ||
// const upload = s3.upload(params); | ||
// upload.on('httpUploadProgress', (progress) => { | ||
// const { loaded, total } = progress; | ||
// /* 非必须 */ | ||
// const percent = Math.round(parseInt(loaded / total) * 100); | ||
// if (typeof onProgress === 'function') onProgress(percent); | ||
// }); | ||
// const uploadPromise = upload.promise(); | ||
// return uploadPromise.then(res => { | ||
// const { key, Key } = res; | ||
// console.log(res); | ||
// // const tempUrl = (key.startsWith('/') ? '' : '/'); | ||
// const fileUrl = `${cdnUrl}${cdnUrl.endsWith('/') ? '' : '/'}${key || Key}` | ||
// if (needWholeRes) { | ||
// return { | ||
// ...res, | ||
// fileUrl | ||
// }; | ||
// } return fileUrl; | ||
// }).catch(err => { | ||
// console.log(err); | ||
// }).finally(_ => { | ||
// }); | ||
// } else | ||
if (type === '2') { // 如果type=2 则使用minIO上传 | ||
console.log(Minio) | ||
@@ -132,0 +133,0 @@ const minioClient = new Minio.Client({ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
597
1324374