@chenminai/cloud-shared 1.0.5 → 1.0.7
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/auth.js +5 -0
- package/package.json +3 -2
- package/storage.js +12 -21
package/auth.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenminai/cloud-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "云函数共享工具:用户身份解析等",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"wx-server-sdk": "~2.6.3",
|
|
10
11
|
"@cloudbase/node-sdk": "^3.18.1"
|
|
11
12
|
}
|
|
12
|
-
}
|
|
13
|
+
}
|
package/storage.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
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
|
-
|
|
9
|
-
function getApp() {
|
|
10
|
-
if (!_app) {
|
|
11
|
-
_app = tcb.init({ env: ENV_ID, secretId: SECRET_ID, secretKey: SECRET_KEY });
|
|
12
|
-
}
|
|
13
|
-
return _app;
|
|
14
|
-
}
|
|
5
|
+
const tcbApp = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* 将 cloud:// fileID 列表批量转为 HTTP 链接。
|
|
@@ -21,20 +12,20 @@ function getApp() {
|
|
|
21
12
|
* @returns {Promise<Map<string, string>>} fileID → HTTP URL
|
|
22
13
|
*/
|
|
23
14
|
async function resolveCloudUrls(fileIds) {
|
|
24
|
-
const cloudIds = fileIds.filter((id) => id.startsWith('cloud://'))
|
|
25
|
-
if (!cloudIds.length) return new Map()
|
|
15
|
+
const cloudIds = fileIds.filter((id) => id.startsWith('cloud://'))
|
|
16
|
+
if (!cloudIds.length) return new Map()
|
|
26
17
|
|
|
27
|
-
const result = await
|
|
18
|
+
const result = await tcbApp.getTempFileURL({ fileList: cloudIds })
|
|
28
19
|
const map = new Map();
|
|
29
20
|
(result.fileList || []).forEach((item) => {
|
|
30
|
-
if (item.
|
|
21
|
+
if (item.code === 'SUCCESS') {
|
|
31
22
|
const url = CUSTOM_DOMAIN
|
|
32
23
|
? item.tempFileURL.replace(/^https?:\/\/[^/]+/, `https://${CUSTOM_DOMAIN}`)
|
|
33
|
-
: item.tempFileURL
|
|
34
|
-
map.set(item.fileID, url)
|
|
24
|
+
: item.tempFileURL
|
|
25
|
+
map.set(item.fileID, `${url}/press`)
|
|
35
26
|
}
|
|
36
|
-
})
|
|
37
|
-
return map
|
|
27
|
+
})
|
|
28
|
+
return map
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
module.exports = { resolveCloudUrls }
|
|
31
|
+
module.exports = { resolveCloudUrls }
|