Download proxy.php from MySafeCode/BytePlus_Seedance_Gallery: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/spaces/MySafeCode/BytePlus_Seedance_Gallery/resolve/main/proxy.php
- Command line
-
hf download hf://spaces/MySafeCode/BytePlus_Seedance_Gallery/proxy.php
-
curl -L -o proxy.php https://huggingface.co/spaces/MySafeCode/BytePlus_Seedance_Gallery/resolve/main/proxy.php
2.52 kB
| $json_file = 'io.json'; | |
| $headers = getallheaders(); | |
| $auth_header = $headers['Authorization'] ?? ''; | |
| $input = file_get_contents('php://input'); | |
| $data = json_decode($input, true); | |
| $method = $_SERVER['REQUEST_METHOD']; | |
| $task_id = $_GET['task_id'] ?? null; | |
| // Read storage | |
| $storage = []; | |
| if (file_exists($json_file)) { | |
| $storage = json_decode(file_get_contents($json_file), true) ?? []; | |
| } | |
| if ($method === 'POST' && !$task_id) { | |
| // CREATE NEW TASK | |
| $ch = curl_init('https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks'); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $input); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
| 'Content-Type: application/json', | |
| 'Authorization: ' . $auth_header | |
| ]); | |
| $response = curl_exec($ch); | |
| $result = json_decode($response, true); | |
| $new_task_id = $result['id'] ?? null; | |
| if ($new_task_id) { | |
| $storage[$new_task_id] = [ | |
| 'created' => time(), | |
| 'status' => 'processing', | |
| 'request' => $data, | |
| 'response' => $result | |
| ]; | |
| file_put_contents($json_file, json_encode($storage, JSON_PRETTY_PRINT)); | |
| } | |
| echo $response; | |
| } elseif ($method === 'GET' && $task_id) { | |
| // POLL EXISTING TASK - THIS UPDATES IO.JSON! | |
| $url = "https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks/{$task_id}"; | |
| $ch = curl_init($url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
| 'Authorization: ' . $auth_header | |
| ]); | |
| $response = curl_exec($ch); | |
| $result = json_decode($response, true); | |
| // UPDATE STORAGE WITH LATEST STATUS | |
| if (isset($storage[$task_id])) { | |
| $storage[$task_id]['response'] = $result; | |
| $storage[$task_id]['status'] = $result['status'] ?? 'unknown'; | |
| $storage[$task_id]['last_poll'] = time(); | |
| if ($result['status'] === 'succeeded') { | |
| $storage[$task_id]['video_url'] = $result['content']['video_url'] ?? null; | |
| } | |
| file_put_contents($json_file, json_encode($storage, JSON_PRETTY_PRINT)); | |
| } | |
| echo $response; | |
| } elseif ($_SERVER['REQUEST_URI'] === '/proxy/io.json') { | |
| // DIRECT ACCESS TO JSON | |
| header('Content-Type: application/json'); | |
| echo file_get_contents($json_file); | |
| } | |