@be-link/cos 1.12.7 → 1.12.8
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/bin/upload.js +13 -5
- package/package.json +1 -1
package/bin/upload.js
CHANGED
|
@@ -62,9 +62,7 @@ async function getTempCredentials(mode) {
|
|
|
62
62
|
|
|
63
63
|
try {
|
|
64
64
|
const response = await fetch(url, { method: 'POST' });
|
|
65
|
-
console.log('🔐 响应:', response);
|
|
66
65
|
const result = await response.json();
|
|
67
|
-
console.log('🔐 结果:', result);
|
|
68
66
|
const data = result?.data || {};
|
|
69
67
|
const credentials = data?.credentials;
|
|
70
68
|
|
|
@@ -121,10 +119,18 @@ async function initCOS() {
|
|
|
121
119
|
const secretId = process.env.COS_SECRET_ID;
|
|
122
120
|
const secretKey = process.env.COS_SECRET_KEY;
|
|
123
121
|
|
|
122
|
+
if (!secretId || !secretKey) {
|
|
123
|
+
console.error('❌ 错误:未找到 COS 密钥配置');
|
|
124
|
+
console.error(' 请设置环境变量:');
|
|
125
|
+
console.error(' - COS_SECRET_ID');
|
|
126
|
+
console.error(' - COS_SECRET_KEY');
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
124
130
|
console.log('✅ 使用环境变量中的密钥');
|
|
125
131
|
cos = new COS({
|
|
126
|
-
SecretId:
|
|
127
|
-
SecretKey:
|
|
132
|
+
SecretId: secretId,
|
|
133
|
+
SecretKey: secretKey,
|
|
128
134
|
});
|
|
129
135
|
|
|
130
136
|
return cos;
|
|
@@ -140,7 +146,7 @@ function upload(url, filename, retryCount = 0, maxRetries = 3) {
|
|
|
140
146
|
reject(new Error('上传参数错误:url 和 filename 不能为空'));
|
|
141
147
|
return;
|
|
142
148
|
}
|
|
143
|
-
|
|
149
|
+
console.log('🔐 上传参数:', { url, filename, bucketConfig, region, projectRemoteUrl });
|
|
144
150
|
cos.putObject(
|
|
145
151
|
{
|
|
146
152
|
Bucket: bucketConfig.name,
|
|
@@ -155,6 +161,8 @@ function upload(url, filename, retryCount = 0, maxRetries = 3) {
|
|
|
155
161
|
// },
|
|
156
162
|
},
|
|
157
163
|
function (err, data) {
|
|
164
|
+
console.log(`🔐 上传结果: ${JSON.stringify(data)}`);
|
|
165
|
+
console.log(`❕ 上传失败: ${JSON.stringify(err)}`);
|
|
158
166
|
if (err) {
|
|
159
167
|
// 重试逻辑
|
|
160
168
|
if (retryCount < maxRetries) {
|