From 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期二, 30 九月 2025 17:38:04 +0800
Subject: [PATCH] feat: 完善比赛晋级功能并清理测试文件

---
 wx/lib/cosUtil.js |   94 ++++++++++++++++++++++++++++-------------------
 1 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/wx/lib/cosUtil.js b/wx/lib/cosUtil.js
index 09220a5..1714af4 100644
--- a/wx/lib/cosUtil.js
+++ b/wx/lib/cosUtil.js
@@ -71,10 +71,16 @@
    * @returns {string} 鍞竴鏂囦欢鍚�
    */
   generateUniqueFileName(originalName) {
-    const timestamp = Date.now()
-    const random = Math.random().toString(36).substring(2, 8)
+    // 鐢熸垚绫讳技UUID鐨勫敮涓�鏍囪瘑绗�
+    const timestamp = Date.now().toString(36)
+    const random1 = Math.random().toString(36).substring(2, 10)
+    const random2 = Math.random().toString(36).substring(2, 10)
+    const random3 = Math.random().toString(36).substring(2, 6)
     const extension = originalName.substring(originalName.lastIndexOf('.'))
-    return `${timestamp}_${random}${extension}`
+    
+    // 鏍煎紡: timestamp-random1-random2-random3.ext
+    // 渚嬪: k8j2l3m4-a1b2c3d4-e5f6g7h8-i9j0.jpg
+    return `${timestamp}-${random1}-${random2}-${random3}${extension}`
   }
 
   /**
@@ -92,43 +98,55 @@
         return
       }
 
-      const cosConfig = app.globalData.cos
-      const uniqueFileName = this.generateUniqueFileName(originalName || 'file.jpg')
-      const key = this.generateFilePath(uniqueFileName, fileType)
+      // 棣栧厛鑾峰彇鏂囦欢淇℃伅锛堝寘鎷枃浠跺ぇ灏忥級
+      wx.getFileInfo({
+        filePath: filePath,
+        success: (fileInfo) => {
+          const cosConfig = app.globalData.cos
+          const uniqueFileName = this.generateUniqueFileName(originalName || 'file.jpg')
+          const key = this.generateFilePath(uniqueFileName, fileType)
 
-      console.log('寮�濮嬩笂浼犳枃浠跺埌COS:', {
-        filePath,
-        fileType,
-        key,
-        bucket: cosConfig.bucket
-      })
-
-      this.cos.uploadFile({
-        Bucket: cosConfig.bucket,
-        Region: cosConfig.region,
-        Key: key,
-        FilePath: filePath,
-        onProgress: (progressData) => {
-          const percent = Math.round(progressData.percent * 100)
-          console.log('涓婁紶杩涘害:', percent + '%')
-          if (onProgress && typeof onProgress === 'function') {
-            onProgress(percent)
-          }
-        }
-      }, (err, data) => {
-        if (err) {
-          console.error('COS涓婁紶澶辫触:', err)
-          reject(err)
-        } else {
-          console.log('COS涓婁紶鎴愬姛:', data)
-          resolve({
-            key: key,
-            url: `https://${data.Location}`,
-            etag: data.ETag,
-            fileName: uniqueFileName,
-            originalName: originalName,
-            fileType: fileType
+          console.log('寮�濮嬩笂浼犳枃浠跺埌COS:', {
+            filePath,
+            fileType,
+            key,
+            fileSize: fileInfo.size,
+            bucket: cosConfig.bucket
           })
+
+          this.cos.uploadFile({
+            Bucket: cosConfig.bucket,
+            Region: cosConfig.region,
+            Key: key,
+            FilePath: filePath,
+            onProgress: (progressData) => {
+              const percent = Math.round(progressData.percent * 100)
+              console.log('涓婁紶杩涘害:', percent + '%')
+              if (onProgress && typeof onProgress === 'function') {
+                onProgress(percent)
+              }
+            }
+          }, (err, data) => {
+            if (err) {
+              console.error('COS涓婁紶澶辫触:', err)
+              reject(err)
+            } else {
+              console.log('COS涓婁紶鎴愬姛:', data)
+              resolve({
+                key: key,
+                url: `https://${data.Location}`,
+                etag: data.ETag,
+                fileName: uniqueFileName,
+                originalName: originalName,
+                fileType: fileType,
+                fileSize: fileInfo.size
+              })
+            }
+          })
+        },
+        fail: (error) => {
+          console.error('鑾峰彇鏂囦欢淇℃伅澶辫触:', error)
+          reject(new Error('鑾峰彇鏂囦欢淇℃伅澶辫触: ' + error.errMsg))
         }
       })
     })

--
Gitblit v1.8.0