%PDF- %PDF-
| Direktori : /home2/rezakur1/yt.rezakurnia.com/ |
| Current File : /home2/rezakur1/yt.rezakurnia.com/config.php |
<?php
/**
* Konfigurasi Supabase + helper functions
*/
// ============================================================
// 🔧 KONFIGURASI - GANTI DENGAN MILIK ANDA
// ============================================================
define('SUPABASE_URL', 'https://ivdvuvumdozhgqcnjlmw.supabase.co');
define('SUPABASE_ANON_KEY', 'sb_publishable_055hZGoY2WDcjSRzz_KR-Q_gt8nwCPm');
// Folder upload
define('UPLOAD_DIR', __DIR__ . '/uploads');
define('UPLOAD_URL_PREFIX', '/uploads');
define('MAX_FILE_SIZE', 500 * 1024 * 1024); // 500MB
// ============================================================
// CORS + JSON headers
// ============================================================
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(204);
exit;
}
// ============================================================
// Helper: Response JSON
// ============================================================
function jsonResponse($data, $code = 200) {
http_response_code($code);
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
function jsonError($message, $code = 400) {
jsonResponse(['success' => false, 'error' => $message], $code);
}
// ============================================================
// Helper: Request body (JSON atau form)
// ============================================================
function getRequestBody() {
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (stripos($contentType, 'application/json') !== false) {
$raw = file_get_contents('php://input');
return json_decode($raw, true) ?: [];
}
return $_POST;
}
// ============================================================
// Helper: Supabase REST API request (pakai cURL)
// ============================================================
function supabaseRequest($endpoint, $method = 'GET', $body = null, $query = '') {
$url = SUPABASE_URL . '/rest/v1/' . $endpoint;
if ($query) {
$url .= '?' . $query;
}
$headers = [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Content-Type: application/json',
'Prefer: return=representation',
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => true,
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return ['success' => false, 'error' => 'cURL error: ' . $error, 'code' => 500];
}
$data = json_decode($response, true);
if ($httpCode >= 400) {
$errMsg = $data['message'] ?? $data['error'] ?? "HTTP $httpCode";
return ['success' => false, 'error' => $errMsg, 'code' => $httpCode, 'raw' => $data];
}
return ['success' => true, 'data' => $data, 'code' => $httpCode];
}
// ============================================================
// Helper: Pastikan folder upload ada
// ============================================================
function ensureUploadDir() {
if (!is_dir(UPLOAD_DIR)) {
mkdir(UPLOAD_DIR, 0755, true);
}
}