Update config.php

This commit is contained in:
Ahyan Z 2026-06-25 17:02:33 +01:00 committed by GitHub
parent 1d259a49a9
commit 9dbad9cd51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,62 +1,65 @@
<?php <?php
/** // ====================================================================
* NostolgaGram Configuration Hub v1.0 // 1. ENVIRONMENT CONFIGURATION & GLOBAL SETTINGS
* Architecture: InfinityFree Core Matrix + Cloudinary CDN Processing // ====================================================================
*/ // Set time zone and ensure clean error reporting for debugging development builds
date_default_timezone_set('UTC');
error_reporting(E_ALL);
ini_set('display_errors', 0); // Keep disabled in production so errors don't corrupt JSON payloads
// 1. Universal Security and Client Handshake Headers // ====================================================================
// Crucial for allowing old Android clients to connect without CORS errors // 2. DATABASE CONFIGURATION (Aiven Cloud Connection Matrix)
header('Content-Type: application/json; charset=utf-8'); // ====================================================================
header("Access-Control-Allow-Origin: *"); // Fall back to standard local development values if variables aren't injected by Vercel
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE"); $db_host = getenv('DB_HOST') ?: 'nostolgagram-nostolgagram.i.aivencloud.com';
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With"); $db_port = getenv('DB_PORT') ?: '3306'; // Default MySQL port (Aiven will overwrite this with 23006 via Vercel)
$db_user = getenv('DB_USER') ?: 'avnadmin';
$db_pass = getenv('DB_PASS') ?: '';
$db_name = 'defaultdb'; // Aiven's default workspace name
// Handle preflight OPTIONS requests instantly before they reach feature files try {
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { // Open a secure database link using the fast, modern PHP Data Objects (PDO) framework
http_response_code(200); $pdo = new PDO(
exit; "mysql:host=$db_host;port=$db_port;dbname=$db_name;charset=utf8mb4",
$db_user,
$db_pass,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
} catch (PDOException $e) {
// If the database connection drops, immediately return a clean JSON error response
// so the patched Instagram 6.20.2 client app doesn't crash or hang.
header('Content-Type: application/json');
http_response_code(500);
echo json_encode([
"error" => "Secure cloud database connection error.",
"status" => "fail"
]);
exit();
} }
// 2. Database Connectivity Profiles // ====================================================================
// Swap these placeholders with your actual keys from your InfinityFree Client Area // 3. MEDIA UPLOAD & STORAGE CONFIGURATION (Cloudinary)
define('DB_HOST', 'sql112.infinityfree.com'); // ====================================================================
define('DB_USER', 'if0_42261255'); // Pull your raw cloudinary:// URL string directly from Vercel's Environment Variables
define('DB_PASS', '8d1WbfEonq'); $cloudinary_env = getenv('CLOUDINARY_URL') ?: 'cloudinary://LOCAL_MOCK_KEY_FOR_TESTING';
define('DB_NAME', 'if0_42261255_nostolgagram');
// 3. Cloudinary Edge CDN Credentials // Define it as a global constant so your existing media/upload scripts run unchanged
// Swap with your actual cloud account name. The preset matches your unsigned configuration. define('CLOUDINARY_URL', $cloudinary_env);
define('CLOUDINARY_CLOUD_NAME', 'dnkm8pijh');
define('CLOUDINARY_UPLOAD_PRESET', 'nostolgagram');
// 4. Global Managed Database Connection Gateway (PDO)
// This function can be safely executed by any file in your directory tree. // ====================================================================
function getDB() { // 4. API UTILITY FUNCTIONS (Optional helper block for your endpoints)
static $dbInstance = null; // ====================================================================
/**
// Reuse existing connection if already established during the request lifecycle * Standardized function to echo clean JSON responses back to the Instagram app
if ($dbInstance !== null) { */
return $dbInstance; function sendJsonResponse($data, $status_code = 200) {
} header('Content-Type: application/json');
http_response_code($status_code);
try { echo json_encode($data);
$dbInstance = new PDO( exit();
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", }
DB_USER,
DB_PASS,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
return $dbInstance;
} catch (PDOException $e) {
// Return structured JSON instead of raw PHP syntax blocks if the database drops
http_response_code(500);
die(json_encode([
"status" => "fail",
"message" => "Database node offline."
]));
}
}