Browse Source

Fix timer and upload

svalavuo 1 ngày trước cách đây
mục cha
commit
8163a50fe4
3 tập tin đã thay đổi với 29 bổ sung3 xóa
  1. 26 0
      backend/api/timers.php
  2. 3 2
      backend/api/upload.php
  3. 0 1
      docker-compose.yml

+ 26 - 0
backend/api/timers.php

@@ -159,6 +159,32 @@ function handlePostRequest() {
             }
             break;
             
+        case 'delete':
+            $data = json_decode(file_get_contents('php://input'), true);
+            $id = $data['id'] ?? null;
+            
+            if ($id) {
+                try {
+                    // Delete timer from database
+                    $query = "DELETE FROM timers WHERE id = ?";
+                    $stmt = $db->prepare($query);
+                    $result = $stmt->execute([$id]);
+                    
+                    if ($result) {
+                        echo json_encode(['success' => true, 'message' => 'Timer deleted successfully']);
+                    } else {
+                        echo json_encode(['success' => false, 'message' => 'Timer not found']);
+                    }
+                } catch (Exception $e) {
+                    http_response_code(500);
+                    echo json_encode(['error' => 'Failed to delete timer: ' . $e->getMessage()]);
+                }
+            } else {
+                http_response_code(400);
+                echo json_encode(['error' => 'Timer ID required']);
+            }
+            break;
+            
         case 'update':
             $data = json_decode(file_get_contents('php://input'), true);
             $id = $data['id'] ?? null;

+ 3 - 2
backend/api/upload.php

@@ -52,8 +52,9 @@ $uploadPath = $uploadDir . $uniqueFileName;
 
 if (move_uploaded_file($tmpName, $uploadPath)) {
     $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
-    $apiPath = dirname($_SERVER['PHP_SELF']);
-    $fullUrl = $baseUrl . $apiPath . '/' . $uploadPath;
+    // Remove /var/www/html/ from the path and create proper URL
+    $relativePath = str_replace('/var/www/html/', '', $uploadPath);
+    $fullUrl = $baseUrl . '/' . $relativePath;
     
     http_response_code(200);
     echo json_encode(array(

+ 0 - 1
docker-compose.yml

@@ -26,7 +26,6 @@ services:
       - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
       - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
     volumes:
-      - uploads_data:/var/www/html/uploads
       - ./uploads:/var/www/html/uploads
       - ./attachments:/var/www/html/attachments
     restart: unless-stopped