@chenminai/cloud-shared 1.0.5 → 1.0.6
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/package.json +1 -1
- package/storage.js +14 -17
package/package.json
CHANGED
package/storage.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
const tcb = require('@cloudbase/node-sdk')
|
|
1
|
+
const tcb = require('@cloudbase/node-sdk')
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const SECRET_ID = process.env.TENCENTCLOUD_SECRETID || '';
|
|
5
|
-
const SECRET_KEY = process.env.TENCENTCLOUD_SECRETKEY || '';
|
|
6
|
-
const CUSTOM_DOMAIN = process.env.STORAGE_CUSTOM_DOMAIN || '';
|
|
3
|
+
const CUSTOM_DOMAIN = process.env.STORAGE_CUSTOM_DOMAIN || ''
|
|
7
4
|
|
|
8
|
-
let _app = null
|
|
5
|
+
let _app = null
|
|
9
6
|
function getApp() {
|
|
10
7
|
if (!_app) {
|
|
11
|
-
_app = tcb.init({ env:
|
|
8
|
+
_app = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
|
|
12
9
|
}
|
|
13
|
-
return _app
|
|
10
|
+
return _app
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
/**
|
|
@@ -21,20 +18,20 @@ function getApp() {
|
|
|
21
18
|
* @returns {Promise<Map<string, string>>} fileID → HTTP URL
|
|
22
19
|
*/
|
|
23
20
|
async function resolveCloudUrls(fileIds) {
|
|
24
|
-
const cloudIds = fileIds.filter((id) => id.startsWith('cloud://'))
|
|
25
|
-
if (!cloudIds.length) return new Map()
|
|
21
|
+
const cloudIds = fileIds.filter((id) => id.startsWith('cloud://'))
|
|
22
|
+
if (!cloudIds.length) return new Map()
|
|
26
23
|
|
|
27
|
-
const result = await getApp().getTempFileURL({ fileList: cloudIds })
|
|
24
|
+
const result = await getApp().getTempFileURL({ fileList: cloudIds })
|
|
28
25
|
const map = new Map();
|
|
29
26
|
(result.fileList || []).forEach((item) => {
|
|
30
|
-
if (item.
|
|
27
|
+
if (item.code === 'SUCCESS') {
|
|
31
28
|
const url = CUSTOM_DOMAIN
|
|
32
29
|
? item.tempFileURL.replace(/^https?:\/\/[^/]+/, `https://${CUSTOM_DOMAIN}`)
|
|
33
|
-
: item.tempFileURL
|
|
34
|
-
map.set(item.fileID, url)
|
|
30
|
+
: item.tempFileURL
|
|
31
|
+
map.set(item.fileID, `${url}/press`)
|
|
35
32
|
}
|
|
36
|
-
})
|
|
37
|
-
return map
|
|
33
|
+
})
|
|
34
|
+
return map
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
module.exports = { resolveCloudUrls }
|
|
37
|
+
module.exports = { resolveCloudUrls }
|