Spaces:
Paused
Paused
| // analyze_receipt.php — Accept pre-extracted receipt (no video upload needed) | |
| // Video stays local. Only the receipt JSON is sent to the HF Space. | |
| require_once __DIR__ . '/config.php'; | |
| ensure_dirs(); | |
| if ($_SERVER['REQUEST_METHOD'] !== 'POST') { | |
| fail_json('POST required', 405); | |
| } | |
| $raw = file_get_contents('php://input'); | |
| $data = json_decode($raw, true); | |
| if (!$data) { | |
| fail_json('Invalid JSON body'); | |
| } | |
| $receipt = $data['receipt'] ?? null; | |
| $format = $data['format'] ?? 'arcade'; | |
| $hfToken = $data['hf_token'] ?? ''; | |
| // Save token if provided (for local mode — token stays on Space only) | |
| if ($hfToken && !getenv('HF_TOKEN')) { | |
| file_put_contents(APP_ROOT . '/.hf_token', $hfToken); | |
| putenv("HF_TOKEN=$hfToken"); | |
| } | |
| if (!$receipt) { | |
| fail_json('No receipt provided'); | |
| } | |
| $id = $receipt['videoId'] ?? safe_id(); | |
| $receipt['videoId'] = $id; | |
| // Save receipt | |
| $outDir = RECEIPT_DIR . "/$id"; | |
| if (!is_dir($outDir)) { | |
| mkdir($outDir, 0775, true); | |
| } | |
| write_json_file("$outDir/receipt.json", $receipt); | |
| // Save job | |
| $job = [ | |
| 'id' => $id, | |
| 'original_name' => $receipt['videoName'] ?? 'local_video', | |
| 'upload_path' => 'LOCAL — not uploaded', | |
| 'extension' => 'local', | |
| 'status' => 'receipt_received', | |
| 'created_at' => time(), | |
| 'source_video_exposed' => false | |
| ]; | |
| write_json_file(RECEIPT_DIR . "/$id.job.json", $job); | |
| json_response([ | |
| 'ok' => true, | |
| 'id' => $id, | |
| 'message' => 'Receipt received. Video stayed local.', | |
| 'token_set' => !empty($hfToken) || getenv('HF_TOKEN') | |
| ]); | |