ichieh commited on
Commit
77adb92
·
1 Parent(s): 902108d

feat: 添加詳細的日誌記錄以追蹤同步問題

Browse files
Files changed (2) hide show
  1. app.py +6 -0
  2. sync_settings.gs +13 -2
app.py CHANGED
@@ -287,15 +287,21 @@ def update_settings():
287
  }
288
  }
289
 
 
 
290
  try:
291
  response = requests.post(
292
  app.config['SETTINGS_SCRIPT_URL'],
293
  json=settings_data,
294
  timeout=10
295
  )
 
 
296
  if not response.ok:
 
297
  app.logger.error(f"Failed to sync settings to Google Sheets: {response.text}")
298
  except Exception as e:
 
299
  app.logger.error(f"Error syncing settings to Google Sheets: {str(e)}")
300
 
301
  return jsonify({'message': '設定已更新'})
 
287
  }
288
  }
289
 
290
+ print(f"Sending settings to Google Sheets: {settings_data}") # 添加日誌
291
+
292
  try:
293
  response = requests.post(
294
  app.config['SETTINGS_SCRIPT_URL'],
295
  json=settings_data,
296
  timeout=10
297
  )
298
+ print(f"Response from Google Sheets: {response.text}") # 添加日誌
299
+
300
  if not response.ok:
301
+ print(f"Failed to sync settings to Google Sheets. Status: {response.status_code}")
302
  app.logger.error(f"Failed to sync settings to Google Sheets: {response.text}")
303
  except Exception as e:
304
+ print(f"Error syncing settings to Google Sheets: {str(e)}")
305
  app.logger.error(f"Error syncing settings to Google Sheets: {str(e)}")
306
 
307
  return jsonify({'message': '設定已更新'})
sync_settings.gs CHANGED
@@ -3,6 +3,9 @@ function doPost(e) {
3
  var data = JSON.parse(e.postData.contents);
4
  var action = data.action;
5
 
 
 
 
6
  if (action === 'backupParticipants') {
7
  // 備份參與者資料
8
  var participantsSheet = sheet.getSheetByName('Participants') || sheet.insertSheet('Participants');
@@ -36,10 +39,14 @@ function doPost(e) {
36
  }
37
 
38
  if (action === 'updateSettings') {
 
 
39
  // 更新設定
40
  var settingsSheet = sheet.getSheetByName('Settings') || sheet.insertSheet('Settings');
41
  var settings = data.settings;
42
 
 
 
43
  // 清除現有設定
44
  settingsSheet.clear();
45
 
@@ -52,8 +59,12 @@ function doPost(e) {
52
  ['每桌人數', settings.seats_per_table]
53
  ]);
54
 
55
- return ContentService.createTextOutput(JSON.stringify({success: true}))
56
- .setMimeType(ContentService.MimeType.JSON);
 
 
 
 
57
  }
58
 
59
  return ContentService.createTextOutput(JSON.stringify({error: 'Invalid action'}))
 
3
  var data = JSON.parse(e.postData.contents);
4
  var action = data.action;
5
 
6
+ Logger.log("Received action: " + action);
7
+ Logger.log("Received data: " + JSON.stringify(data));
8
+
9
  if (action === 'backupParticipants') {
10
  // 備份參與者資料
11
  var participantsSheet = sheet.getSheetByName('Participants') || sheet.insertSheet('Participants');
 
39
  }
40
 
41
  if (action === 'updateSettings') {
42
+ Logger.log("Updating settings...");
43
+
44
  // 更新設定
45
  var settingsSheet = sheet.getSheetByName('Settings') || sheet.insertSheet('Settings');
46
  var settings = data.settings;
47
 
48
+ Logger.log("Settings to update: " + JSON.stringify(settings));
49
+
50
  // 清除現有設定
51
  settingsSheet.clear();
52
 
 
59
  ['每桌人數', settings.seats_per_table]
60
  ]);
61
 
62
+ Logger.log("Settings updated successfully");
63
+
64
+ return ContentService.createTextOutput(JSON.stringify({
65
+ success: true,
66
+ message: 'Settings updated successfully'
67
+ })).setMimeType(ContentService.MimeType.JSON);
68
  }
69
 
70
  return ContentService.createTextOutput(JSON.stringify({error: 'Invalid action'}))