Comparing version 1.1.0 to 1.1.1
@@ -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' |
{ | ||
"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 | ||
}); | ||
} |
130
upload.js
@@ -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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
2248197
13
28445
1
19
1
80
6
1
+ Addedminio@^7.1.3
+ Added@zxing/text-encoding@0.9.0(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedblock-stream2@2.1.0(transitive)
+ Addedbrowser-or-node@2.1.1(transitive)
+ Addedbuffer-crc32@1.0.0(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedfast-xml-parser@4.5.1(transitive)
+ Addedfilter-obj@1.1.0(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@2.2.0(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminio@7.1.4(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedquery-string@7.1.3(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsplit-on-first@1.1.0(transitive)
+ Addedstream-chain@2.2.5(transitive)
+ Addedstream-json@1.9.1(transitive)
+ Addedstrict-uri-encode@2.0.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrnum@1.0.5(transitive)
+ Addedthrough2@4.0.2(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedweb-encoding@1.1.5(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedxml2js@0.5.0(transitive)
+ Addedxmlbuilder@11.0.1(transitive)