@chenminai/cloud-shared 1.0.1 → 1.0.2

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 +1 -2
  2. package/storage.js +10 -5
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@chenminai/cloud-shared",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",
11
10
  "@cloudbase/js-sdk": "^3.3.10"
12
11
  }
13
12
  }
package/storage.js CHANGED
@@ -1,20 +1,25 @@
1
1
  /**
2
2
  * 云函数存储工具
3
3
  *
4
- * 封装 @cloudbase/js-sdk 的 getTempFileURL,统一处理:
4
+ * 使用 @cloudbase/js-sdk 的 getTempFileURL,统一处理:
5
5
  * - cloud:// fileID → HTTP 临时链接
6
6
  * - 自定义域名替换(STORAGE_CUSTOM_DOMAIN 环境变量)
7
7
  */
8
8
 
9
9
  const cloudbase = require('@cloudbase/js-sdk');
10
10
 
11
+ const ENV_ID = process.env.TCB_ENV_ID || process.env.SCF_NAMESPACE || '';
12
+ const SECRET_ID = process.env.TENCENTCLOUD_SECRETID || '';
13
+ const SECRET_KEY = process.env.TENCENTCLOUD_SECRETKEY || '';
11
14
  const CUSTOM_DOMAIN = process.env.STORAGE_CUSTOM_DOMAIN || '';
12
15
 
13
16
  let _app = null;
14
-
15
17
  function getApp() {
16
18
  if (!_app) {
17
- _app = cloudbase.init({ env: cloudbase.SYMBOL_CURRENT_ENV });
19
+ _app = cloudbase.init({
20
+ env: ENV_ID,
21
+ auth: { secretId: SECRET_ID, secretKey: SECRET_KEY },
22
+ });
18
23
  }
19
24
  return _app;
20
25
  }
@@ -30,9 +35,9 @@ async function resolveCloudUrls(fileIds) {
30
35
  const cloudIds = fileIds.filter((id) => id.startsWith('cloud://'));
31
36
  if (!cloudIds.length) return new Map();
32
37
 
33
- const { fileList } = await getApp().getTempFileURL({ fileList: cloudIds });
38
+ const result = await getApp().getTempFileURL({ fileList: cloudIds });
34
39
  const map = new Map();
35
- (fileList || []).forEach((item) => {
40
+ (result.fileList || []).forEach((item) => {
36
41
  if (item.code === 'SUCCESS' && item.tempFileURL) {
37
42
  const url = CUSTOM_DOMAIN
38
43
  ? item.tempFileURL.replace(/^https?:\/\/[^/]+/, `https://${CUSTOM_DOMAIN}`)