Download api/services/SupabaseService.php from felix-fx/fx-craft: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/felix-fx/fx-craft/resolve/main/api/services/SupabaseService.php
- Command line
-
hf download hf://spaces/felix-fx/fx-craft/api/services/SupabaseService.php
-
curl -L -o SupabaseService.php https://huggingface.co/spaces/felix-fx/fx-craft/resolve/main/api/services/SupabaseService.php
1.56 kB
| // /api/services/SupabaseService.php | |
| class SupabaseService { | |
| private string $url; | |
| private string $serviceKey; | |
| public function __construct(string $url, string $serviceKey) { | |
| $this->url = $url; | |
| $this->serviceKey = $serviceKey; | |
| } | |
| /** | |
| * حفظ بيانات الإضافة في Supabase. | |
| */ | |
| public function saveAddon(array $addonData): array { | |
| $url = $this->url . '/rest/v1/addons'; | |
| $ch = curl_init($url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($addonData)); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
| 'apikey: ' . $this->serviceKey, | |
| 'Authorization: Bearer ' . $this->serviceKey, | |
| 'Content-Type: application/json', | |
| 'Prefer: return=representation' | |
| ]); | |
| $response = curl_exec($ch); | |
| $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| curl_close($ch); | |
| if ($httpCode >= 400) { | |
| $errorData = json_decode($response, true); | |
| $errorMessage = $errorData['message'] ?? $errorData['error'] ?? $response; | |
| throw new Exception("فشل حفظ البيانات في Supabase: " . $errorMessage); | |
| } | |
| $data = json_decode($response, true); | |
| if (json_last_error() !== JSON_ERROR_NONE) { | |
| throw new Exception("فشل في تحليل استجابة Supabase: " . json_last_error_msg()); | |
| } | |
| return $data; | |
| } | |
| } | |