@be-link/cos 1.12.2 → 1.12.3

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/bin/upload.js +23 -1
  2. package/package.json +1 -1
package/bin/upload.js CHANGED
@@ -57,38 +57,54 @@ let cos = null;
57
57
  */
58
58
  function getTempCredentials(mode) {
59
59
  return new Promise((resolve, reject) => {
60
+ console.log('🔐 环境模式:', mode);
60
61
  const url =
61
62
  mode === 'production'
62
63
  ? 'https://shield-60660-10-1304510571.sh.run.tcloudbase.com/config/get-cos-temp-secret'
63
64
  : 'https://shield-74680-5-1304510571.sh.run.tcloudbase.com/config/get-cos-temp-secret';
64
65
 
65
66
  const urlObj = new URL(url);
67
+ const postData = JSON.stringify({});
68
+
66
69
  const options = {
67
70
  hostname: urlObj.hostname,
68
71
  path: urlObj.pathname,
69
72
  method: 'POST',
70
73
  headers: {
71
74
  'Content-Type': 'application/json',
75
+ 'Content-Length': Buffer.byteLength(postData),
72
76
  },
73
77
  };
74
78
 
79
+ console.log('🔐 请求 URL:', url);
80
+ console.log('🔐 请求选项:', options);
81
+
75
82
  const req = https.request(options, (res) => {
76
83
  let data = '';
77
84
 
85
+ console.log('🔐 响应状态码:', res.statusCode);
86
+ console.log('🔐 响应头:', res.headers);
87
+
78
88
  res.on('data', (chunk) => {
79
89
  data += chunk;
80
90
  });
81
91
 
82
92
  res.on('end', () => {
93
+ console.log('🔐 原始响应数据:', data);
94
+
83
95
  try {
84
96
  const result = JSON.parse(data);
97
+ console.log('🔐 解析后的响应:', JSON.stringify(result, null, 2));
98
+
85
99
  const credentials = result?.data?.credentials;
86
100
 
87
101
  if (!credentials) {
102
+ console.error('❌ 返回数据结构:', result);
88
103
  reject(new Error('获取临时密钥失败:返回数据格式错误'));
89
104
  return;
90
105
  }
91
106
 
107
+ console.log('✅ 密钥信息获取成功');
92
108
  resolve({
93
109
  TmpSecretId: credentials.tmpSecretId,
94
110
  TmpSecretKey: credentials.tmpSecretKey,
@@ -97,15 +113,20 @@ function getTempCredentials(mode) {
97
113
  ExpiredTime: result.data.expiredTime,
98
114
  });
99
115
  } catch (err) {
116
+ console.error('❌ JSON 解析失败:', err.message);
117
+ console.error('❌ 原始数据:', data);
100
118
  reject(new Error('解析临时密钥响应失败:' + err.message));
101
119
  }
102
120
  });
103
121
  });
104
122
 
105
123
  req.on('error', (err) => {
124
+ console.error('❌ 请求错误:', err);
106
125
  reject(new Error('请求临时密钥失败:' + err.message));
107
126
  });
108
127
 
128
+ // 发送请求体
129
+ req.write(postData);
109
130
  req.end();
110
131
  });
111
132
  }
@@ -123,7 +144,8 @@ async function initCOS() {
123
144
  // 方式1:尝试通过云函数获取临时密钥(推荐)
124
145
  console.log('🔐 正在获取临时密钥...');
125
146
  const credentials = await getTempCredentials(mode || 'development');
126
- console.log('✅ 临时密钥获取成功,有效期至:', new Date(credentials.ExpiredTime * 1000).toLocaleString());
147
+ console.log('✅ 临时密钥获取成功');
148
+ console.log(' 有效期至:', new Date(credentials.ExpiredTime * 1000).toLocaleString());
127
149
 
128
150
  cos = new COS({
129
151
  getAuthorization: (options, callback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/cos",
3
- "version": "1.12.2",
3
+ "version": "1.12.3",
4
4
  "description": "前端项目产物上传cos",
5
5
  "homepage": "https://github.com/snowmountain-top/be-link#readme",
6
6
  "author": "zhuiyi",