Spaces:
Running
Running
Download bh-raw-proxy.php from SamiKoen/BF-Realtime: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/SamiKoen/BF-Realtime/resolve/main/bh-raw-proxy.php
- Command line
-
hf download hf://spaces/SamiKoen/BF-Realtime/bh-raw-proxy.php
-
curl -L -o bh-raw-proxy.php https://huggingface.co/spaces/SamiKoen/BF-Realtime/resolve/main/bh-raw-proxy.php
2.3 kB
| /** | |
| * BizimHesap ham JSON aynasi β SALT-OKUR snapshot sunucusu. | |
| * | |
| * BizimHesap'a ASLA cagri yapmaz. bh-collector.php'nin saatte 1 yazdigi | |
| * cache/bh-raw/ snapshot'larini servis eder. Boylece kullanici trafigi | |
| * hicbir kosulda BizimHesap trafigi uretemez (Cloudflare 1015 onlemi). | |
| * | |
| * Kullanim: | |
| * ?kind=products | |
| * ?kind=warehouses | |
| * ?kind=inventory&id=<warehouse_id> | |
| */ | |
| header('Content-Type: application/json; charset=utf-8'); | |
| header('Access-Control-Allow-Origin: *'); | |
| header('Access-Control-Allow-Methods: GET, OPTIONS'); | |
| header('Access-Control-Allow-Headers: Content-Type'); | |
| if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { | |
| http_response_code(200); | |
| exit(); | |
| } | |
| define('SNAP_DIR', __DIR__ . '/cache/bh-raw/'); | |
| $VALID = ['products', 'warehouses', 'inventory']; | |
| $kind = $_GET['kind'] ?? ''; | |
| $wid = $_GET['id'] ?? ''; | |
| if (!in_array($kind, $VALID, true) || ($kind === 'inventory' && !preg_match('/^[A-F0-9]{32}$/i', $wid))) { | |
| http_response_code(400); | |
| echo json_encode(['resultCode' => 0, 'errorText' => 'gecersiz kind/id parametresi', 'data' => null]); | |
| exit; | |
| } | |
| $file = SNAP_DIR . ($kind === 'inventory' ? "inventory_{$wid}.json" : "{$kind}.json"); | |
| if (!file_exists($file)) { | |
| http_response_code(503); | |
| header('X-Cache: no-snapshot'); | |
| echo json_encode(['resultCode' => 0, 'errorText' => 'snapshot henuz yok (collector bekleniyor)', 'data' => null]); | |
| exit; | |
| } | |
| $age = time() - filemtime($file); | |
| // Bayatlik tetigi: snapshot 70dk'dan eskiyse toplayiciyi YEREL olarak durt. | |
| // Bu istek BizimHesap'a degil ayni sunucudaki bh-collector.php'ye gider; | |
| // collector kendini kisitlar (50dk tazelik + flock + 429 devre kesici). | |
| // 200ms'de koparilir β collector ignore_user_abort ile calismaya devam eder. | |
| // Boylece tetikleme HF Space'e muhtac degil: sistemi kullanan herkes canli tutar. | |
| if ($age > 4200) { | |
| $ch = curl_init('https://video.trek-turkey.com/bh-collector.php?key=trkbh2026x'); | |
| curl_setopt_array($ch, [ | |
| CURLOPT_RETURNTRANSFER => true, | |
| CURLOPT_TIMEOUT_MS => 200, | |
| CURLOPT_NOSIGNAL => true, | |
| CURLOPT_SSL_VERIFYPEER => false, | |
| CURLOPT_SSL_VERIFYHOST => false, | |
| ]); | |
| @curl_exec($ch); | |
| curl_close($ch); | |
| } | |
| header('X-Cache: snapshot'); | |
| header('X-Snapshot-Age: ' . $age); | |
| readfile($file); | |