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.1.0 to 1.1.1

dist/fhcommon.min.js.LICENSE.txt

8

index.js

@@ -0,1 +1,9 @@

// import FHCommon from './dist/fhcommon.min.js'
// if (typeof window !== 'undefined' && window.Vue) {
// window.Vue.use(FHCommon)
// window.FHUpload = FHCommon
// }
// // expose FHCommon as default export
// export default FHCommon;
import { upload, compressFile, loopCompressFile } from './upload'

@@ -2,0 +10,0 @@ import { getDomImage } from './packages/html2canvas'

21

package.json
{
"name": "fhcommon",
"version": "1.1.0",
"version": "1.1.1",
"description": "泛华前端的上传方法",
"main": "dist/fhcommon.min.js",
"module": "dist/fhcommon.min.js",
"dependencies": {},
"devDependencies": {
"babel-loader": "^9.1.3",
"crypto-browserify": "^3.12.0",
"css-loader": "^6.7.4",
"eslint": "^9.0.0",
"https-browserify": "^1.0.0",
"less-loader": "^11.1.4",
"path-browserify": "^1.0.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"style-loader": "^3.3.3",
"terser-webpack-plugin": "^5.3.10",
"timers-browserify": "^2.0.12",
"uglify-js": "^3.17.4",
"uglifyjs-webpack-plugin": "^2.2.0",
"vm-browserify": "^1.1.2",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.7.16",
"webpack": "^5.91.0",
"webpack-cli": "^3.3.12",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^5.0.4"

@@ -27,3 +33,6 @@ },

"author": "",
"license": "ISC"
}
"license": "ISC",
"dependencies": {
"minio": "^7.1.3"
}
}

@@ -9,9 +9,10 @@ import { loadJavaScript } from "../../upload";

export function getDomImage (el) {
export function getDomImage (el,type = 'file',scale = 2,options={}) {
if(!el)return
const {scaleRate = 1} = options
return html2canvas(el, {
allowTaint: false,
// allowTaint: true,
useCORS: true,
width: el.offsetWidth,
innerHeight: el.offsetHeight,
width: el.offsetWidth * scaleRate,
innerHeight: el.offsetHeight * scaleRate,
windowWidth: document.body.scrollWidth,

@@ -21,9 +22,10 @@ windowHeight: document.body.scrollHeight,

y: 0,
scale: 1.5,
scale,
dpi: 300,
}).then(canvas => {
const base64 = canvas.toDataURL('image/png')
const file = base64ToBlob(base64)
console.log('Canvas Dimensions:', canvas.width, canvas.height, type, scale); // 输出画布尺寸
let file = canvas.toDataURL('image/png')
if (type === 'file') file = base64ToBlob(file)
return file
});
}

@@ -23,3 +23,11 @@

}
import * as Minio from 'minio'
// const Minio = require('minio')
// if (!window.Minio) {
// loadJavaScript('https://unpkg.com/minio@8.0.1/dist/main/minio.js', () => {
// console.log('Minio 加载成功',window.Client)
// })
// }
/**

@@ -46,3 +54,4 @@ * 第一个参数的可选属性

export function upload ({ file, target, project = '0', keyFunc, needWholeRes }, onProgress) {
const defaultTarget = (location.origin.includes('https://smnguat.fhrons.net') || location.origin.includes('https://openuat.fhrons.net') || location.origin.includes('https://smng.avantech.io') || location.origin.includes('https://open.avantech.io') || process.env.VUE_APP_ENV_CONFIG && process.env.VUE_APP_ENV_CONFIG.includes('hk') || process.env.VUE_APP_ENV_CONFIG && process.env.VUE_APP_ENV_CONFIG === 'poc') ? 'amazon' : 'tencent';
let defaultTarget = (location.origin.includes('https://smnguat.fhrons.net') || location.origin.includes('https://openuat.fhrons.net') || location.origin.includes('https://smng.avantech.io') || location.origin.includes('https://open.avantech.io') || process.env.VUE_APP_ENV_CONFIG && process.env.VUE_APP_ENV_CONFIG.includes('hk')) ? '1' : '0';
defaultTarget = process.env.VUE_APP_ENV_CONFIG && process.env.VUE_APP_ENV_CONFIG.includes('poc') ? '2' : defaultTarget
target = target || defaultTarget

@@ -55,3 +64,4 @@ if (!file) {

if (file.file) file = file.file // vant文件选择器选到的文件里还有一层file
target = target === 'tencent' ? '0' : '1'; // 根据传进来的target转换
// target = target === 'tencent' ? '0' : '1'; // 根据传进来的target转换
// target = '2'
const filename = file.name;

@@ -67,3 +77,3 @@ const appName = process.env.VUE_APP_NAME || 'common';

* @tmpSecretKey 临时访问密钥的密钥。
* @type 0腾讯/1亚马逊 字符串格式
* @type 0腾讯/1亚马逊/2 minio 字符串格式
* @startTime 腾讯使用的字段,开始时间

@@ -112,3 +122,23 @@ * @expiredTime 腾讯使用的字段,过期时间

});
} // 腾讯 如果没有type 则默认使用腾讯上传
} else if (type === '2') { // 如果type=2 则使用minIO上传
const minioClient = new Minio.Client({
endPoint: '172.16.9.7',
port: 31003,
useSSL: false,
accessKey: tmpSecretId,
secretKey: tmpSecretKey,
sessionToken: token
})
// console.log(Minio, minioClient, '---------------------------')
// multipartUpload(file, minioClient, bucketName, newKey, cdnUrl, needWholeRes).then(res => {
// console.log(res, '分段上传')
// })
return uploadFileToMinio(file, minioClient, bucketName, newKey, cdnUrl, needWholeRes).then(res => {
return res
}).catch(err => {
console.log(err);
})
}
// 腾讯 如果没有type 则默认使用腾讯上传
const cos = new COS({

@@ -157,2 +187,92 @@ getAuthorization: function (options, callback) {

// function multipartUpload (file, minioClient, bucketName, newKey, cdnUrl, needWholeRes) {
// return new Promise(async (resolve, reject) => {
// // console.log('准备开始初始化', bucketName, newKey)
// // const metaData = { 'Content-Type': 'application/octet-stream' };
// // const uploadId = await minioClient.initiateNewMultipartUpload(bucketName, newKey, metaData)
// // const chunkSize = 5 * 1024 * 100
// // const chunks = Math.ceil(file.size / chunkSize)
// // let parts = []
// // for (let i = 0; i < chunks; i++) {
// // const partNumber = i + 1
// // const chunk = file.slice(i * chunkSize, partNumber * chunkSize)
// // // minioClient.uploadPart({ bucketName, objectName: newKey, uploadID: uploadId, partNumber }, (err, result) => {
// // // if (err) {
// // // console.log(err)
// // // reject(err)
// // // } else {
// // // console.log(result, '-----------------')
// // // }
// // // })
// // // console.log(etag, '---------------')
// // // 获取预签名URL
// // // const presignedUrl = await minioClient.presignedUrl('PUT', bucketName, newKey, 24 * 60 * 60, {
// // // partNumber: partNumber,
// // // uploadId: uploadId
// // // });
// // // // 上传分片
// // // const response = await fetch(presignedUrl, {
// // // method: 'PUT',
// // // body: chunk,
// // // headers: {
// // // 'Content-Type': 'application/octet-stream',
// // // }
// // // });
// // // if (response.ok) {
// // // const etag = response.headers.get('ETag')
// // // parts.push({ partNumber, etag: etag })
// // // } else {
// // // reject(`Error uploading part ${partNumber}`)
// // // }
// // }
// console.log(parts, uploadId)
// // try {
// // // 完成上传 合并分块
// // minioClient.completeMultipartUpload(bucketName, newKey, uploadId, parts, (err, result) => {
// // if (err) {
// // reject('err', err)
// // } else {
// // console.log(result)
// // resolve(result)
// // }
// // })
// // } catch (err) {
// // reject(err)
// // }
// })
// }
function uploadFileToMinio (file, minioClient, bucketName, newKey, cdnUrl, needWholeRes) {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = function (e) {
try {
const buffer = Buffer.from(e.target.result)
minioClient.putObject(bucketName, newKey, buffer, function (err, etag) {
if (err) {
console.log(err)
return err
}
console.log(etag, Minio, minioClient)
if (needWholeRes) {
resolve({
etag,
fileUrl: `${cdnUrl}/${newKey}`
})
}
resolve(`${cdnUrl}/${newKey}`);
})
} catch (err) {
reject(err)
}
}
reader.onerror = function (err) {
reject(err)
}
reader.readAsArrayBuffer(file)
})
}
/**

@@ -187,3 +307,3 @@ * @param {Blob} file 上传的图片文件

// 循环压缩
export async function loopCompressFile (file, size, quality) {
export async function loopCompressFile (file, size, quality) {
if (!size) {

@@ -190,0 +310,0 @@ return new Error('size 不能为空')

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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