Commit 42814efb by 岑成威

fix:统一格式化jpg

1 parent e41073c5
{
"name": "glsk-oss-jssdk",
"version": "1.0.6",
"version": "1.0.7",
"description": "glsk-oss-jssdk",
"main": "src/index.js",
"scripts": {
......
......@@ -4,6 +4,7 @@ import OssConfigService from '../api/ossConfigService' // 导入配置服务
class GlOssApi {
constructor(params = {}) {
this.baseConfig = null
this.defaultImageProcess = params?.defaultImageProcess ?? 'image/format,jpg'
}
/**
......@@ -25,8 +26,9 @@ class GlOssApi {
* @param {Object} compressObj 压缩配置对象(可选)
* @param {number} partSize 分片大小(单位 KB,默认500KB)
* @param {number} maxRetries 最大重试次数(默认3次)
* @param {string|null} imageProcess OSS图片处理参数(可选),例如:'image/format,png'。传null表示不拼接x-oss-process
*/
async multipartUpload(file, successCallback = () => {}, errCallBack = () => {}, bucketName = 'zzl-filerepostorypublic', dir = 'image', custAttrObj = { systemSource: 'dj' }, compressObj = {}, partSize = 500, maxRetries = 3) {
async multipartUpload(file, successCallback = () => {}, errCallBack = () => {}, bucketName = 'zzl-filerepostorypublic', dir = 'image', custAttrObj = { systemSource: 'dj' }, compressObj = {}, partSize = 500, maxRetries = 3, imageProcess = null) {
try {
// 获取基础配置并动态设置baseURL到httpClient
this.baseConfig = await OssConfigService.fetchBaseConfig()
......@@ -70,9 +72,15 @@ class GlOssApi {
const url = aliyunAddress.split('?')[0].split('https:')[1]
const encodedUrl = this.encodeOSSFilename(decodeURIComponent(url))
const finalImageProcess = imageProcess ?? this.defaultImageProcess
const publicUrl = `https:${encodedUrl}`
const processedUrl = finalImageProcess
? `${publicUrl}?x-oss-process=${encodeURIComponent(finalImageProcess)}`
: publicUrl
successCallback({
attachment: fileName,
aliyunAddress: `https:${encodedUrl}`,
aliyunAddress: processedUrl,
size
})
} catch (err) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!