Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fhcommon

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fhcommon - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc