From bec58fa7fe4fae2deac88200d8d939e12ec8a08f Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期五, 03 十月 2025 22:26:39 +0800
Subject: [PATCH] 修复小程序WXS日期显示问题并重新设计【我的】页面

---
 web/src/api/media.js |  113 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 62 insertions(+), 51 deletions(-)

diff --git a/web/src/api/media.js b/web/src/api/media.js
index 6c7afdc..ac6a772 100644
--- a/web/src/api/media.js
+++ b/web/src/api/media.js
@@ -86,42 +86,23 @@
 };
 
 export const deleteMedia = async (id) => {
-  console.log('=== deleteMedia API璋冪敤 ===');
-  console.log('瑕佸垹闄ょ殑濯掍綋ID:', id);
-  console.log('GraphQL鏌ヨ:', DELETE_MEDIA_MUTATION);
-  
-  // 鑾峰彇JWT token
-  const { getToken } = await import('@/utils/auth');
-  const token = getToken();
-  const headers = { 'Content-Type': 'application/json' };
-  if (token) {
-    headers['Authorization'] = `Bearer ${token}`;
+  try {
+    const variables = { id: parseInt(id) };
+    
+    // 鍙戦�丟raphQL璇锋眰
+    const result = await graphqlRequest(DELETE_MEDIA_MUTATION, variables);
+    
+    // 妫�鏌ヨ繑鍥炵粨鏋�
+    const deleteResult = result.data?.deleteMedia;
+    
+    return deleteResult;
+  } catch (error) {
+    throw new Error(`鍒犻櫎濯掍綋澶辫触: ${error.message}`);
   }
-  
-  const res = await fetch(GRAPHQL_ENDPOINT, {
-    method: 'POST',
-    headers: headers,
-    body: JSON.stringify({
-      query: DELETE_MEDIA_MUTATION,
-      variables: { id: id.toString() }
-    })
-  });
-  const result = await res.json();
-  console.log('GraphQL鍝嶅簲:', result);
-  console.log('deleteMedia缁撴灉:', result.data?.deleteMedia);
-  
-  if (result.errors) {
-    console.error('GraphQL閿欒:', result.errors);
-    throw new Error(result.errors[0].message);
-  }
-  
-  const deleteResult = result.data.deleteMedia;
-  console.log('杩斿洖鐨勫垹闄ょ粨鏋�:', deleteResult, '绫诲瀷:', typeof deleteResult);
-  return deleteResult;
 };
 
-// 涓婁紶鏂囦欢鍒版湇鍔″櫒
-export const uploadFile = async (file) => {
+// 涓婁紶鏂囦欢鍒版湇鍔″櫒锛堝甫閲嶈瘯鏈哄埗锛�
+export const uploadFile = async (file, maxRetries = 3) => {
   const formData = new FormData();
   formData.append('file', file);
   
@@ -133,18 +114,56 @@
     headers['Authorization'] = `Bearer ${token}`;
   }
   
-  const response = await fetch('http://localhost:8080/api/upload/image', {
-    method: 'POST',
-    headers: headers,
-    body: formData
-  });
+  let lastError;
   
-  const result = await response.json();
-  if (!result.success) {
-    throw new Error(result.error || '涓婁紶澶辫触');
+  for (let attempt = 1; attempt <= maxRetries; attempt++) {
+    try {
+      const response = await fetch('http://localhost:8080/api/upload/image', {
+        method: 'POST',
+        headers: headers,
+        body: formData,
+        // 娣诲姞瓒呮椂璁剧疆
+        signal: AbortSignal.timeout(30000) // 30绉掕秴鏃�
+      });
+      
+      if (!response.ok) {
+        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
+      }
+      
+      const result = await response.json();
+      if (!result.success) {
+        throw new Error(result.error || '涓婁紶澶辫触');
+      }
+      
+      return result;
+    } catch (error) {
+      lastError = error;
+      console.warn(`鏂囦欢涓婁紶绗�${attempt}娆″皾璇曞け璐�:`, error.message);
+      
+      // 濡傛灉鏄渶鍚庝竴娆″皾璇曪紝鎴栬�呮槸闈炵綉缁滈敊璇紝鐩存帴鎶涘嚭
+      if (attempt === maxRetries || 
+          (!error.message.includes('Failed to fetch') && 
+           !error.message.includes('ERR_CONNECTION_RESET') &&
+           !error.message.includes('ERR_NETWORK'))) {
+        break;
+      }
+      
+      // 绛夊緟涓�娈垫椂闂村悗閲嶈瘯锛堟寚鏁伴��閬匡級
+      const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
+      await new Promise(resolve => setTimeout(resolve, delay));
+    }
   }
   
-  return result;
+  // 鎻愪緵鏇村弸濂界殑閿欒淇℃伅
+  if (lastError.message.includes('Failed to fetch') || 
+      lastError.message.includes('ERR_CONNECTION_RESET') ||
+      lastError.message.includes('ERR_NETWORK')) {
+    throw new Error('缃戠粶杩炴帴澶辫触锛岃妫�鏌ョ綉缁滆繛鎺ユ垨绋嶅悗閲嶈瘯');
+  } else if (lastError.message.includes('timeout')) {
+    throw new Error('涓婁紶瓒呮椂锛岃妫�鏌ョ綉缁滆繛鎺ユ垨绋嶅悗閲嶈瘯');
+  } else {
+    throw new Error(`涓婁紶澶辫触: ${lastError.message}`);
+  }
 };
 
 // 涓婁紶瑙嗛鏂囦欢骞惰嚜鍔ㄧ敓鎴愮缉鐣ュ浘
@@ -152,17 +171,11 @@
   const { extractVideoFrame, generateThumbnailFileName } = await import('@/utils/video.js');
   
   try {
-    console.log('寮�濮嬪鐞嗚棰戞枃浠�:', videoFile.name);
-    
-    // 1. 涓婁紶鍘熻棰戞枃浠�
-    console.log('涓婁紶瑙嗛鏂囦欢...');
+    // 1. 涓婁紶瑙嗛鏂囦欢
     const videoUploadResult = await uploadFile(videoFile);
-    console.log('瑙嗛涓婁紶鎴愬姛:', videoUploadResult);
     
     // 2. 鎻愬彇瑙嗛绗竴甯�
-    console.log('鎻愬彇瑙嗛绗竴甯�...');
     const thumbnailBlob = await extractVideoFrame(videoFile);
-    console.log('瑙嗛甯ф彁鍙栨垚鍔燂紝澶у皬:', thumbnailBlob.size);
     
     // 3. 鍒涘缓缂╃暐鍥炬枃浠跺璞�
     const thumbnailFileName = generateThumbnailFileName(videoFile.name);
@@ -171,9 +184,7 @@
     });
     
     // 4. 涓婁紶缂╃暐鍥�
-    console.log('涓婁紶缂╃暐鍥�...');
     const thumbnailUploadResult = await uploadFile(thumbnailFile);
-    console.log('缂╃暐鍥句笂浼犳垚鍔�:', thumbnailUploadResult);
     
     // 5. 杩斿洖鍖呭惈瑙嗛鍜岀缉鐣ュ浘淇℃伅鐨勭粨鏋�
     return {

--
Gitblit v1.8.0