@smart100/spu-web-plugin 1.0.0 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/nativeApi.ts CHANGED
@@ -1,12 +1,9 @@
1
- import { globalOptions, axios, getUser, Module } from './index'
2
- import { get, cloneDeep } from 'lodash-es'
3
- import login from './login'
4
- import { getIndextagSync } from './apaasSpuTrack'
1
+ import { getUser } from './login'
5
2
  import core from './core'
6
3
 
7
4
  class NativeApi {
8
5
  // 已经注入api的或者不同域的就不再注入
9
- checkIsCanInject (iframe: any) {
6
+ checkIsCanInject(iframe: any) {
10
7
  try {
11
8
  return !iframe?.contentWindow?.Module || !!iframe?.contentWindow?.Module
12
9
  } catch (err) {
@@ -16,16 +13,16 @@ class NativeApi {
16
13
  }
17
14
  }
18
15
 
19
- injectApi (iframe: any, options: any) {
16
+ injectApi(iframe: any, options: any) {
20
17
  const modulekey = options.modulekey
21
18
  // const modulekey = 'demospu'
22
19
 
23
20
  const Module = {
24
21
  spuContainerType: '',
25
- getContextSync () {
22
+ getContextSync() {
26
23
  return core.getContextSync(modulekey)
27
24
  },
28
- getIndextagSync: getIndextagSync,
25
+ getIndextagSync: core.getIndextagSync.bind(core),
29
26
  checkPermission: core.checkPermission.bind(core),
30
27
  linkToPage: window?.Module?.linkToPage,
31
28
  linkToModule: window?.Module?.linkToModule,
@@ -39,7 +36,7 @@ class NativeApi {
39
36
  }
40
37
 
41
38
  const aPaaS = {
42
- getUserInfoSync: login.getUser.bind(login),
39
+ getUserInfoSync: getUser,
43
40
  getToken: window?.aPaaS?.getToken
44
41
  }
45
42
 
@@ -48,7 +45,7 @@ class NativeApi {
48
45
  iframe.contentWindow.aPaaS = aPaaS
49
46
  }
50
47
 
51
- inject (iframe: any, options: any) {
48
+ inject(iframe: any, options: any) {
52
49
  if (this.checkIsCanInject(iframe) && options?.modulekey) {
53
50
  this.injectApi(iframe, options)
54
51
  }
@@ -0,0 +1,20 @@
1
+ import OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
2
+ // const OSS = require('../package/ali-oss/aliyun-oss-sdk.apaas.min.js')
3
+
4
+ import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
5
+ // const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
6
+
7
+ // import '../package/aws-sdk/aws-sdk.min.js'
8
+ import 'aws-sdk/dist/aws-sdk.min.js'
9
+ // var S3 = require('aws-sdk/clients/s3')
10
+ // import S3 from 'aws-sdk/clients/s3'
11
+ // import S3 from 'aws-sdk'
12
+ // import S3 from 'aws-sdk/dist/aws-sdk.js'
13
+ // import * as S3 from 'aws-sdk/dist/aws-sdk.js'
14
+ // import AWS from '../package/aws-sdk/aws-sdk.min.js'
15
+ // import * as AWS from 'aws-sdk'
16
+
17
+ const AliClient = OSS
18
+ const S3Client = window?.AWS?.S3
19
+
20
+ export { AliClient, ObsClient, S3Client }
@@ -1,16 +1,9 @@
1
- import OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
2
- // import * as OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
3
- // const OSS = require('../package/ali-oss/aliyun-oss-sdk.apaas.min.js')
4
- import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
5
- // import * as ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
6
- // const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
7
-
8
- import 'aws-sdk/dist/aws-sdk.min.js'
9
-
1
+ import { AliClient, ObsClient, S3Client } from './OSSClient'
10
2
  import dayjs from 'dayjs'
11
3
  import cloudServ from '../cloudServ'
12
4
  import { initServToken } from './servtoken'
13
- import { axios, getUser } from '../index'
5
+ import { axios } from '../axios'
6
+ import { getUser } from '../login'
14
7
  // import { get } from 'lodash-es'
15
8
  // import qs from 'qs'
16
9
 
@@ -22,8 +15,6 @@ import { axios, getUser } from '../index'
22
15
  // return path.split('/')
23
16
  // }
24
17
 
25
- // console.log(OSS)
26
- // debugger
27
18
  const getContentType = (suffix: string) => {
28
19
  const map: IAny = {
29
20
  '.jpg': 'image/jpeg',
@@ -68,61 +59,65 @@ const isIpUrl = (url: string) => {
68
59
  // }
69
60
  // }
70
61
 
71
- type Cope = { width?: number, height?: number } | string | boolean
62
+ type Cope = { width?: number | string; height?: number | string } | string | boolean
72
63
 
73
- interface IDownload {
74
- type?: 'att' | 'img',
75
- source: string,
76
- datetime: string | number,
77
- storagetype?: StorageType,
78
- cope?: Cope,
79
- filename?: string, // 下载文件名
80
- }
81
-
82
-
83
- const getNormalizeAliOssCopeMinio = (cope?: Cope) => {
84
- let copeObj = ''
64
+ const getAliyunCope = (cope?: Cope) => {
65
+ let str = ''
85
66
  if (cope) {
86
67
  if (cope === true) {
87
- copeObj = 'image/resize,m_fixed,w_100,h_100'
68
+ str = 'image/resize,m_fixed,w_100,h_100'
88
69
  } else if (typeof cope === 'string') {
89
- // 'image/resize,m_fixed,w_100,h_100'
90
- copeObj = cope
70
+ str = cope
91
71
  } else if (cope.width || cope.height) {
92
- copeObj = 'image/resize,m_fixed'
93
- if (cope.width && !cope.height) {
94
- copeObj += `,w_${cope.width},h_${cope.width}`
95
- } else if (cope.height && !cope.width) {
96
- copeObj += `,w_${cope.height},h_${cope.height}`
97
- } else if (cope.width && cope.height) {
98
- copeObj += `,w_${cope.width},h_${cope.height}`
72
+ str = 'image/resize,m_fixed'
73
+ if (cope.width) {
74
+ const width = String(cope.width).replace('px', '')
75
+ str += `,w_${width}`
76
+ }
77
+ if (cope.height) {
78
+ const height = String(cope.height).replace('px', '')
79
+ str += `,h_${height}`
99
80
  }
100
81
  }
101
82
  }
102
- return copeObj
83
+ return str
103
84
  }
104
85
 
105
- const getNormalizeAliOssCope = (cope?: Cope) => {
106
- let copeObj = ''
86
+ const getCope = (cope?: Cope) => {
87
+ let str = ''
107
88
  if (cope) {
108
89
  if (cope === true) {
109
- copeObj = 'image/resize,m_fixed,w_100,h_100'
90
+ str = 'image/resize,m_fixed,w_100,h_100'
110
91
  } else if (typeof cope === 'string') {
111
- // 'image/resize,m_fixed,w_100,h_100'
112
- copeObj = cope
92
+ str = cope
113
93
  } else if (cope.width || cope.height) {
114
- copeObj = 'image/resize,m_fixed'
115
- if (cope.width) {
116
- copeObj += `,w_${cope.width}`
117
- }
118
- if (cope.height) {
119
- copeObj += `,h_${cope.height}`
94
+ str = 'image/resize,m_fixed'
95
+ let width = ''
96
+ let height = ''
97
+ if (cope.width && !cope.height) {
98
+ width = String(cope.width).replace('px', '')
99
+ height = width
100
+ } else if (cope.height && !cope.width) {
101
+ height = String(cope.height).replace('px', '')
102
+ width = height
103
+ } else if (cope.width && cope.height) {
104
+ width = String(cope.width).replace('px', '')
105
+ height = String(cope.height).replace('px', '')
120
106
  }
107
+ str += `,w_${width},h_${height}`
121
108
  }
122
109
  }
123
- return copeObj
110
+ return str
124
111
  }
125
112
 
113
+ interface IDownload {
114
+ type?: 'att' | 'img'
115
+ source: string
116
+ datetime: string | number
117
+ storagetype?: StorageType
118
+ cope?: Cope
119
+ filename?: string // 下载文件名
120
+ }
126
121
 
127
122
  // 根据文件信息最后生成一个云文件服务可以用的链接http://xxxxx.xxx.jpg
128
123
  const getUrl = async ({
@@ -144,15 +139,16 @@ const getUrl = async ({
144
139
  if (!filename) {
145
140
  filename = source
146
141
  }
147
- const isAbsoluteUrl = !!source.match(/\/att\//) || !!source.match(/\/img\//) || !!source.match(/att\//) || !!source.match(/img\//)
142
+ const isAbsoluteUrl =
143
+ !!source.match(/\/att\//) || !!source.match(/\/img\//) || !!source.match(/att\//) || !!source.match(/img\//)
148
144
  const suffix = filename.slice(filename.lastIndexOf('.'))
149
145
  const date = dayjs(+datetime).format('YYYYMMDD')
150
146
  let objectKey = isAbsoluteUrl ? source : `${source.slice(0, 3)}/${type}/${date}/${tenantCode}/${source}`
151
- const copeObj = provider?.isMinio ? getNormalizeAliOssCopeMinio(cope) : getNormalizeAliOssCope(cope)
147
+ const copeStr = provider?.isAliyun ? getAliyunCope(cope) : getCope(cope)
152
148
  const contentType = getContentType(suffix)
153
149
 
154
150
  if (provider?.isAliyun) {
155
- const ossClient = new OSS({
151
+ const ossClient = new AliClient({
156
152
  // region: storageConfig.cloudserv_storage_storageendpoint,
157
153
  endpoint: storageConfig.cloudserv_storage_storageendpoint,
158
154
  accessKeyId: servToken.accesskeyid,
@@ -173,7 +169,7 @@ const getUrl = async ({
173
169
 
174
170
  const ossUrl = ossClient.signatureUrl(objectKey, {
175
171
  response: responseHeader,
176
- process: copeObj
172
+ process: copeStr
177
173
  })
178
174
 
179
175
  // // 假阿里云会自动拼cloudserv_storage_storagebucket,这里要去掉
@@ -203,9 +199,9 @@ const getUrl = async ({
203
199
  // Expires: 3600,
204
200
  // Headers: headers
205
201
  }
206
- if (contentType.startsWith('image') && copeObj) {
202
+ if (contentType.startsWith('image') && copeStr) {
207
203
  Params.QueryParams = {
208
- 'x-image-process': copeObj
204
+ 'x-image-process': copeStr
209
205
  }
210
206
  }
211
207
  const res = obs.createSignedUrlSync(Params)
@@ -220,7 +216,6 @@ const getUrl = async ({
220
216
  throw Error(e)
221
217
  }
222
218
  } else if (provider?.isMinio) {
223
- const S3 = window?.AWS?.S3
224
219
  const s3Params: IAny = {
225
220
  accessKeyId: servToken.accesskeyid,
226
221
  secretAccessKey: servToken.accesskeysecret,
@@ -233,7 +228,7 @@ const getUrl = async ({
233
228
  if (provider?.isMinio || isIpUrl(storageConfig.cloudserv_storage_storageurl)) {
234
229
  s3Params.s3ForcePathStyle = true
235
230
  }
236
- const s3 = new S3(s3Params)
231
+ const s3 = new S3Client(s3Params)
237
232
 
238
233
  // awss3缩略图没方案处理
239
234
  const params = {
@@ -249,8 +244,8 @@ const getUrl = async ({
249
244
  console.error(err)
250
245
  reject(new Error(err))
251
246
  } else {
252
- if (provider?.isMinio && copeObj) {
253
- data = `${data}&x-oss-process=${copeObj}`
247
+ if (provider?.isMinio && copeStr) {
248
+ data = `${data}&x-oss-process=${copeStr}`
254
249
  // data = `${data}&x-oss-process=image/resize,m_fixed,w_100,h_`
255
250
  }
256
251
  resolve(data)
@@ -268,7 +263,6 @@ const getUrl = async ({
268
263
  }
269
264
  }
270
265
 
271
-
272
266
  const downloadFileByUrl = (url: string, filename: string) => {
273
267
  const aElm = document.createElement('a')
274
268
  aElm.innerHTML = filename
@@ -303,13 +297,16 @@ const downloadFile = async ({
303
297
  cope = '',
304
298
  filename = ''
305
299
  }: IDownload) => {
306
-
307
300
  if (!filename) {
308
301
  filename = source
309
302
  }
310
303
 
311
304
  const suffix = filename.slice(filename.lastIndexOf('.'))
312
- const realFilename = filename.replace(suffix, '') + dayjs(+datetime).format('_YYYYMMDDHHmmssS') + String(Math.floor(Math.random() * 9000) + 1000) + suffix
305
+ const realFilename =
306
+ filename.replace(suffix, '') +
307
+ dayjs(+datetime).format('_YYYYMMDDHHmmssS') +
308
+ String(Math.floor(Math.random() * 9000) + 1000) +
309
+ suffix
313
310
 
314
311
  // console.log(filename)
315
312
  const url = await getUrl({
@@ -337,18 +334,21 @@ const downloadFile = async ({
337
334
  if (provider?.isAliyun) {
338
335
  downloadFileByUrl(url, filename)
339
336
  } else {
340
- axios.get(url, {
341
- responseType: 'blob',
342
- isSendToken: false,
343
- isShowErrorMessage: false
344
- }).then((response: any) => {
345
- // console.log(response)
346
- // debugger
347
- downloadFileByBlob(response.data, filename)
348
- }).catch((e: any) => {
349
- console.log(e)
350
- throw Error(e)
351
- })
337
+ axios
338
+ .get(url, {
339
+ responseType: 'blob',
340
+ isSendToken: false,
341
+ isShowErrorMessage: false
342
+ })
343
+ .then((response: any) => {
344
+ // console.log(response)
345
+ // debugger
346
+ downloadFileByBlob(response.data, filename)
347
+ })
348
+ .catch((e: any) => {
349
+ console.log(e)
350
+ throw Error(e)
351
+ })
352
352
  }
353
353
  }
354
354
 
package/src/oss/index.ts CHANGED
@@ -1,8 +1,4 @@
1
-
2
1
  import downloadService from './downloadService'
3
2
  import uploadService from './uploadService'
4
3
 
5
- export {
6
- downloadService,
7
- uploadService
8
- }
4
+ export { downloadService, uploadService }
@@ -90,7 +90,7 @@ export const obsMultiUpload = async (obs: any, file: File | Blob, options: IMult
90
90
  }
91
91
  }
92
92
 
93
- const executeTasks = async <T> (tasks: Array<ITask<T>>, parallel = 3): Promise<Array<T>> => {
93
+ const executeTasks = async <T>(tasks: Array<ITask<T>>, parallel = 3): Promise<Array<T>> => {
94
94
  return new Promise((resolve, reject) => {
95
95
  const todos = tasks.slice(0, parallel)
96
96
  const pendings = tasks.slice(parallel)
@@ -109,9 +109,12 @@ const executeTasks = async <T> (tasks: Array<ITask<T>>, parallel = 3): Promise<A
109
109
  const todoIndex = tasks.findIndex((task) => {
110
110
  return task === todo
111
111
  })
112
- return todo && todo()
113
- .then((todoRes) => dealPending(todoRes, todoIndex))
114
- .catch(reject)
112
+ return (
113
+ todo &&
114
+ todo()
115
+ .then((todoRes) => dealPending(todoRes, todoIndex))
116
+ .catch(reject)
117
+ )
115
118
  }
116
119
  if (!pendings.length) {
117
120
  const running = todos.map((todo) => {
@@ -1,5 +1,4 @@
1
- // import { noBaseRequest } from '@/service/http'
2
- import { axios } from '../index'
1
+ import { axios } from '../axios'
3
2
 
4
3
  export type ServToken = {
5
4
  accesskeyid: string
@@ -21,7 +20,7 @@ let xhr: Promise<ServToken> | null = null
21
20
 
22
21
  const getServToken = async () => {
23
22
  try {
24
- const response: ServToken = await axios.get('/api/teapi/auth/servtoken', {}).then((res: any) => res.data)
23
+ const response: ServToken = await axios.get('/api/teapi/auth/servtoken').then((res: any) => res.data)
25
24
  // debugger
26
25
  return response
27
26
  } catch (e) {
@@ -71,8 +70,6 @@ export const initServToken = () => {
71
70
  .catch(() => {
72
71
  xhr = null
73
72
  isGetting = false
74
- // return null
75
- // eslint-disable-next-line prefer-promise-reject-errors
76
73
  reject(null)
77
74
  })
78
75
  } else {
@@ -82,50 +79,3 @@ export const initServToken = () => {
82
79
  }
83
80
  })
84
81
  }
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
- // // let last = 0
95
- // // let servtoken
96
- // let isRequesting = false
97
- // const getServToken = function () {
98
- // let servtoken = wx.getStorageSync('servtoken')
99
- // let last
100
- // if (servtoken) {
101
- // last = new Date(servtoken.expiration).getTime()
102
- // }
103
- // const now = Date.now()
104
- // if (!servtoken || (last - now < (1000 * 60 * 5))) {
105
- // wx.removeStorageSync('servtoken')
106
- // if (!isRequesting) {
107
- // isRequesting = true
108
- // return request({
109
- // url: `${api.HOST}/api/teapi/auth/servtoken`,
110
- // method: 'get',
111
- // isShowLoading: false
112
- // }).then((res) => {
113
- // wx.setStorageSync('servtoken', res.data.resp_data)
114
- // isRequesting = false
115
- // return res.data.resp_data
116
- // })
117
- // } else {
118
- // return new Promise((resolve, reject) => {
119
- // const fn = setInterval(() => {
120
- // let servtoken = wx.getStorageSync('servtoken')
121
- // if (servtoken) {
122
- // resolve(servtoken)
123
- // clearInterval(fn)
124
- // }
125
- // }, 200)
126
- // })
127
- // }
128
- // } else {
129
- // return Promise.resolve(servtoken)
130
- // }
131
- // }
@@ -1,35 +1,19 @@
1
- import OSS from '../package/ali-oss/aliyun-oss-sdk.apaas.min.js'
2
- // const OSS = require('../package/ali-oss/aliyun-oss-sdk.apaas.min.js')
3
-
4
- import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js'
5
- // const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
6
-
7
- // import '../package/aws-sdk/aws-sdk.min.js'
8
- import 'aws-sdk/dist/aws-sdk.min.js'
9
- // var S3 = require('aws-sdk/clients/s3')
10
- // import S3 from 'aws-sdk/clients/s3'
11
- // import S3 from 'aws-sdk'
12
- // import S3 from 'aws-sdk/dist/aws-sdk.js'
13
- // import * as S3 from 'aws-sdk/dist/aws-sdk.js'
14
- // import AWS from '../package/aws-sdk/aws-sdk.min.js'
15
- // import * as AWS from 'aws-sdk'
16
-
1
+ import { AliClient, ObsClient, S3Client } from './OSSClient'
17
2
  import { v4 as uuidv4 } from 'uuid'
18
3
  import dayjs from 'dayjs'
19
4
  import co from 'co'
20
5
 
21
- import { getUser } from '../index'
6
+ import { getUser } from '../login'
22
7
  import cloudServ from '../cloudServ'
23
8
  import { initServToken } from './servtoken'
24
9
  import { obsMultiUpload } from './multiUpload'
25
10
 
26
-
27
11
  interface IUpload {
28
- type?: 'att' | 'img',
29
- file: File,
30
- source?: string,
31
- datetime?: string | number,
32
- storagetype?: StorageType,
12
+ type?: 'att' | 'img'
13
+ file: File
14
+ source?: string
15
+ datetime?: string | number
16
+ storagetype?: StorageType
33
17
  onprogress?: (p: number, _checkpoint?: IAny) => void
34
18
  }
35
19
 
@@ -39,7 +23,7 @@ const upload = async ({
39
23
  source = '',
40
24
  datetime = '',
41
25
  storagetype = 'storage',
42
- onprogress,
26
+ onprogress
43
27
  }: IUpload) => {
44
28
  if (!file) throw Error('请传入文件')
45
29
  const storageConfig = cloudServ.get(storagetype)
@@ -50,10 +34,10 @@ const upload = async ({
50
34
  const provider = cloudServ.getProvider(storagetype)
51
35
  const tenantCode = getUser('tenantcode')
52
36
  const suffix = '.' + file.name.substring(file.name.lastIndexOf('.') + 1)
53
- source = source ? source : (uuidv4() + suffix)
37
+ source = source ? source : uuidv4() + suffix
54
38
  datetime = datetime ? datetime : Date.now()
55
39
  const date = dayjs(+datetime).format('YYYYMMDD')
56
- const objectKey = `${source.slice(0, 3)}/${type}/${date}/${tenantCode}/${source}`
40
+ const osskey = `${source.slice(0, 3)}/${type}/${date}/${tenantCode}/${source}`
57
41
 
58
42
  // console.log(file)
59
43
  // console.log(source)
@@ -63,7 +47,7 @@ const upload = async ({
63
47
  // debugger
64
48
  const promise = new Promise(async (resolve, reject) => {
65
49
  if (provider?.isAliyun) {
66
- const ossClient = new OSS({
50
+ const ossClient = new AliClient({
67
51
  // region: storageConfig.cloudserv_storage_storageendpoint,
68
52
  endpoint: storageConfig.cloudserv_storage_storageendpoint,
69
53
  accessKeyId: servToken.accesskeyid,
@@ -73,7 +57,7 @@ const upload = async ({
73
57
  secure: true
74
58
  })
75
59
  co(function* () {
76
- yield ossClient.multipartUpload(objectKey, file, {
60
+ yield ossClient.multipartUpload(osskey, file, {
77
61
  headers: {
78
62
  'Content-Disposition': 'filename="' + (file.name && encodeURIComponent(file.name)) // 阿里云提供的下载名字
79
63
  },
@@ -87,6 +71,7 @@ const upload = async ({
87
71
  type: file.type,
88
72
  date: date,
89
73
  datetime: datetime,
74
+ storage: storagetype,
90
75
  file
91
76
  })
92
77
  }
@@ -97,59 +82,56 @@ const upload = async ({
97
82
  reject(error)
98
83
  })
99
84
  } else if (provider?.isHuawei) {
100
- const obs = new ObsClient({
101
- access_key_id: servToken.accesskeyid,
102
- secret_access_key: servToken.accesskeysecret,
103
- server: storageConfig.cloudserv_storage_storageendpoint,
104
- security_token: servToken.securitytoken
85
+ const obs = new ObsClient({
86
+ access_key_id: servToken.accesskeyid,
87
+ secret_access_key: servToken.accesskeysecret,
88
+ server: storageConfig.cloudserv_storage_storageendpoint,
89
+ security_token: servToken.securitytoken
90
+ })
91
+ // const obs = new ObsClient({
92
+ // access_key_id: '75ISL4GWAOOO1USWUMRG',
93
+ // secret_access_key: 'srn6eJ1BpFbjxoFrJgiQjeS65Z3eKC3rnqeyBBlL',
94
+ // server: storageConfig.cloudserv_storage_storageendpoint,
95
+ // security_token: 'gQ5jbi1zb3V0aHdlc3QtMogAsKjYcI5CQldRAvQQJysdkZ7tAt6arLsoWHFGCaco8s8FPk6wtbslHWhvg2SZh3QMM4aUA4FhPEWQt9A7gXoC_Lh4DpF6hhHIxUyACKgakNHNPdPegy5G9-sibBXkGueIY1X3K12tzpjbyd08esLKEEu-M_QmfDoDdkgOcyidITc-lOg5EzXb27f91Ym26u2mAMTaNjCLRulJ4rziLSW6IAprSx8LUkuQQE-wUz-tMzVL9oFiVykHz980o0Y0CNdCIwn98Y-xbMdslZ3U8raydy6Wnf2LchXc0ajvMix0gg-CV0tpA4cgiZFqPxwEDXSv42hvfccboWlpGmOVR3llHLUirrlgFod8rhm-Rmk6MIfQw4NA8rddow1Gx6g-MugFV5arMDLfsOhqeSFQRJWizb3q50zk6GcUFulewitxP8HSkXMGt_rDDYCcCEmdu15D3imX5431Mbdt0qCgxH80OPCDmFXw0xMOsggxE0PBVexVY2x3wHGeql3JNyevUZAhqlskNNu77ui2Vnp-ZbHMcxgDLcPuAULINId4V_QGdhAkDaxQk53AE237DAFXtlyWWaBRMsTNVnpq9mCXJup9pdBbjLRVAO4OxfYVnwwvl-w_mb-xCgOf5EPHqA_zbZF8z-ad6JjWgLOQCHaawE7kNGHIQwAgzneik33wP2jPlG1ak9KEWyXr1n2QMJCmDM3bIrRit5_8LLFoPjXcwurBjZ-AomM_ztOe34sdr357atlQcPD7a2xWtrvn9mnqqndg12m7QxnwkmJsOYK4ZO5Hoyb2vd_NX2Nd9PaSIVAcFw=='
96
+ // })
97
+ try {
98
+ const uploadRes = await obsMultiUpload(obs, file, {
99
+ bucket: storageConfig.cloudserv_storage_storagebucket,
100
+ key: osskey,
101
+ parallel: 3,
102
+ onProgress: (percent: number) => {
103
+ onprogress && onprogress(percent)
104
+ }
105
105
  })
106
- // const obs = new ObsClient({
107
- // access_key_id: '75ISL4GWAOOO1USWUMRG',
108
- // secret_access_key: 'srn6eJ1BpFbjxoFrJgiQjeS65Z3eKC3rnqeyBBlL',
109
- // server: storageConfig.cloudserv_storage_storageendpoint,
110
- // security_token: 'gQ5jbi1zb3V0aHdlc3QtMogAsKjYcI5CQldRAvQQJysdkZ7tAt6arLsoWHFGCaco8s8FPk6wtbslHWhvg2SZh3QMM4aUA4FhPEWQt9A7gXoC_Lh4DpF6hhHIxUyACKgakNHNPdPegy5G9-sibBXkGueIY1X3K12tzpjbyd08esLKEEu-M_QmfDoDdkgOcyidITc-lOg5EzXb27f91Ym26u2mAMTaNjCLRulJ4rziLSW6IAprSx8LUkuQQE-wUz-tMzVL9oFiVykHz980o0Y0CNdCIwn98Y-xbMdslZ3U8raydy6Wnf2LchXc0ajvMix0gg-CV0tpA4cgiZFqPxwEDXSv42hvfccboWlpGmOVR3llHLUirrlgFod8rhm-Rmk6MIfQw4NA8rddow1Gx6g-MugFV5arMDLfsOhqeSFQRJWizb3q50zk6GcUFulewitxP8HSkXMGt_rDDYCcCEmdu15D3imX5431Mbdt0qCgxH80OPCDmFXw0xMOsggxE0PBVexVY2x3wHGeql3JNyevUZAhqlskNNu77ui2Vnp-ZbHMcxgDLcPuAULINId4V_QGdhAkDaxQk53AE237DAFXtlyWWaBRMsTNVnpq9mCXJup9pdBbjLRVAO4OxfYVnwwvl-w_mb-xCgOf5EPHqA_zbZF8z-ad6JjWgLOQCHaawE7kNGHIQwAgzneik33wP2jPlG1ak9KEWyXr1n2QMJCmDM3bIrRit5_8LLFoPjXcwurBjZ-AomM_ztOe34sdr357atlQcPD7a2xWtrvn9mnqqndg12m7QxnwkmJsOYK4ZO5Hoyb2vd_NX2Nd9PaSIVAcFw=='
111
- // })
112
- try {
113
- const uploadRes = await obsMultiUpload(obs, file, {
114
- bucket: storageConfig.cloudserv_storage_storagebucket,
115
- key: objectKey,
116
- parallel: 3,
117
- onProgress: (percent: number) => {
118
- onprogress && onprogress(percent)
119
- }
106
+ if (uploadRes) {
107
+ resolve({
108
+ source,
109
+ filename: file.name,
110
+ type: file.type,
111
+ date: date,
112
+ datetime: datetime,
113
+ storage: storagetype,
114
+ file
120
115
  })
121
- if (uploadRes) {
122
- resolve({
123
- source,
124
- filename: file.name,
125
- type: file.type,
126
- date: date,
127
- datetime: datetime,
128
- file
129
- })
130
- }
131
- } catch (e) {
132
- console.error(e)
133
- reject(e)
134
116
  }
135
- // obs.putObject({
136
- // Bucket: cloudServ.cloudserv_storage_storagebucket,
137
- // Key: objectKey,
138
- // SourceFile: file
139
- // }, (err, result) => {
140
- // result.CommonMsg.Status
141
- // console.error(err)
142
- // console.log(result)
143
- // debugger
144
- // })
117
+ } catch (e) {
118
+ console.error(e)
119
+ reject(e)
120
+ }
121
+ // obs.putObject({
122
+ // Bucket: cloudServ.cloudserv_storage_storagebucket,
123
+ // Key: osskey,
124
+ // SourceFile: file
125
+ // }, (err, result) => {
126
+ // result.CommonMsg.Status
127
+ // console.error(err)
128
+ // console.log(result)
129
+ // debugger
130
+ // })
145
131
  } else if (provider?.isMinio || provider?.isAwss3) {
146
- // console.error(9874)
147
- // console.log(S3)
148
- // console.log(window.AWS)
149
- const S3 = window?.AWS?.S3
150
132
  // debugger
151
133
  // debugger
152
- const s3 = new S3({
134
+ const s3 = new S3Client({
153
135
  accessKeyId: servToken.accesskeyid,
154
136
  secretAccessKey: servToken.accesskeysecret,
155
137
  sessionToken: servToken.securitytoken,
@@ -160,13 +142,15 @@ const upload = async ({
160
142
  })
161
143
  const params = {
162
144
  Bucket: storageConfig.cloudserv_storage_storagebucket,
163
- Key: objectKey,
145
+ Key: osskey,
164
146
  Body: file
165
147
  }
166
148
  const upload = s3.upload(params, {}).on('httpUploadProgress', (e: any) => {
167
149
  const precent: any = parseInt(e.loaded, 10) / parseInt(e.total, 10)
168
- // console.log('httpUploadProgress', e)
169
- onprogress && onprogress(precent.toFixed(2))
150
+ // console.log('httpUploadProgress')
151
+ // console.log(e)
152
+ // console.log(precent)
153
+ onprogress && onprogress(precent)
170
154
  })
171
155
  upload.send((err: any, data: any) => {
172
156
  if (err) {
@@ -174,11 +158,13 @@ const upload = async ({
174
158
  reject(err)
175
159
  } else {
176
160
  resolve({
161
+ key: osskey,
177
162
  source,
178
163
  filename: file.name,
179
164
  type: file.type,
180
165
  date: date,
181
166
  datetime: datetime,
167
+ storage: storagetype,
182
168
  file
183
169
  })
184
170
  }