@chenminai/cloud-shared 1.0.4 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/storage.js +14 -17
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@chenminai/cloud-shared",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "云函数共享工具:用户身份解析等",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "dependencies": {
10
- "@cloudbase/node-sdk": "^3.0.0"
10
+ "@cloudbase/node-sdk": "^3.18.1"
11
11
  }
12
12
  }
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 ENV_ID = process.env.TCB_ENV_ID || process.env.SCF_NAMESPACE || '';
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: ENV_ID, secretId: SECRET_ID, secretKey: SECRET_KEY });
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.status === 0 && item.tempFileURL) {
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 }