mcp-cos-upload 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.
- package/package.json +1 -1
- package/src/index.js +28 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -209,6 +209,25 @@ async function main() {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
// 生成随机字符串(6-8位)
|
|
213
|
+
const generateRandomStr = (len = 6) => {
|
|
214
|
+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
215
|
+
let result = "";
|
|
216
|
+
for (let i = 0; i < len; i++) {
|
|
217
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// 获取当前日期目录(YYYY-MM-DD)
|
|
223
|
+
const getDateFolder = () => {
|
|
224
|
+
const now = new Date();
|
|
225
|
+
const year = now.getFullYear();
|
|
226
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
227
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
228
|
+
return `${year}-${month}-${day}`;
|
|
229
|
+
};
|
|
230
|
+
|
|
212
231
|
// 自动生成 key
|
|
213
232
|
if (!key) {
|
|
214
233
|
if (!ext) {
|
|
@@ -237,8 +256,16 @@ async function main() {
|
|
|
237
256
|
}
|
|
238
257
|
}
|
|
239
258
|
|
|
259
|
+
// 添加随机字符防止文件名冲突
|
|
260
|
+
const randomSuffix = generateRandomStr(6);
|
|
261
|
+
const finalFilename = `${filename}_${randomSuffix}`;
|
|
262
|
+
|
|
263
|
+
// 构建 key: prefix/日期目录/文件名.扩展名
|
|
240
264
|
const prefix = (folder || KEY_PREFIX || "").replace(/^\/+|\/+$/g, "");
|
|
241
|
-
const
|
|
265
|
+
const dateFolder = getDateFolder();
|
|
266
|
+
const keyParts = prefix
|
|
267
|
+
? [prefix, dateFolder, `${finalFilename}.${ext}`]
|
|
268
|
+
: [dateFolder, `${finalFilename}.${ext}`];
|
|
242
269
|
key = keyParts.join("/");
|
|
243
270
|
}
|
|
244
271
|
|