zerof images loading updates & stats

This commit is contained in:
merelendor 2024-04-30 16:29:23 +03:00
parent 846a7220fd
commit b5b1c328bd

View File

@ -168,8 +168,12 @@ function OnEpilogHandler()
\Bitrix\Main\Application::getInstance()->getExceptionHandler()->setHandlerOutput(new HttpExceptionHandlerOutput());
function zerof_request($path, $query)
function zerof_request($path, $query, $timeout = 900)
{
print "zerof_request | ".$path."\n";
print_r($query);
print "\n";
$key_sha1 = strtoupper(sha1(ZEROF_PASSWORD, false));
$date = gmdate('D, d M Y H:i:s T');
@ -196,24 +200,44 @@ function zerof_request($path, $query)
}
$request = curl_init();
curl_setopt($request, CURLOPT_TIMEOUT, 900);
curl_setopt($request, CURLOPT_TIMEOUT, $timeout);
curl_setopt($request, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($request) or die(curl_error($request));
$response = curl_exec($request);
$http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
print "ZEROF response code ".$http_code."\n";
if($http_code != 200)
{
print_r($response);
print "\n";
$check = md5($path.var_export($query, true));
$check_file = file_get_contents($_SERVER['DOCUMENT_ROOT']."/zerof-500.txt");
if(strpos($check_file, $check) < 0)
{
file_put_contents($_SERVER['DOCUMENT_ROOT']."/zerof-500.txt", $path."\n".var_export($query, true)."\n".$http_code." | ".$response."\n\n");
print "response with error logged\n";
}
print "\n";
//die();
}
curl_close($request);
sleep(1);
return $http_code === 200 ? $response : false;
}
function zerof_get_images($task_uid)
{
print "zerof_get_images | ".$task_uid."\n";
$images = [];
$tasks_car_in_new = zerof_request("/v2/tasks/find", [ "status" => "new", "value" => $task_uid, "profile" => 703 ]);
$tasks_car_in_process = zerof_request("/v2/tasks/find", [ "status" => "process", "value" => $task_uid, "profile" => 703 ]);
$tasks_car_in_pass = zerof_request("/v2/tasks/find", [ "status" => "pass", "value" => $task_uid, "profile" => 703 ]);
@ -228,6 +252,13 @@ function zerof_get_images($task_uid)
$tasks_trucks_in_pass_data = json_decode(html_entity_decode($tasks_trucks_in_pass), true);
$tasks_trucks_in_new_data = json_decode(html_entity_decode($tasks_trucks_in_new), true);
$tasks_car_in_process_data = is_array($tasks_car_in_process_data) ? $tasks_car_in_process_data : [];
$tasks_car_in_pass_data = is_array($tasks_car_in_pass_data) ? $tasks_car_in_pass_data : [];
$tasks_car_in_new_data = is_array($tasks_car_in_new_data) ? $tasks_car_in_new_data : [];
$tasks_trucks_in_process_data = is_array($tasks_trucks_in_process_data) ? $tasks_trucks_in_process_data : [];
$tasks_trucks_in_pass_data = is_array($tasks_trucks_in_pass_data) ? $tasks_trucks_in_pass_data : [];
$tasks_trucks_in_new_data = is_array($tasks_trucks_in_new_data) ? $tasks_trucks_in_new_data : [];
$tasks = array_merge(
$tasks_car_in_process_data[array_keys($tasks_car_in_process_data)[0]],
$tasks_car_in_pass_data[array_keys($tasks_car_in_pass_data)[0]],
@ -238,34 +269,49 @@ function zerof_get_images($task_uid)
);
print "\n".$task_uid." TASKS:\n";
print_r($tasks[0]);
if(isset($tasks[0]))
foreach($tasks AS $task_entry)
{
$task_string = zerof_request("/v2/tasks/".$tasks[0]['id'], null);
$task = json_decode(html_entity_decode($task_string), true);
print "TASK:\n";
print_r($task);
foreach($task['views'][0]['files'] AS $file)
if(trim($task_entry['title']) === trim($task_uid))
{
$image = zerof_request("/v2/tasks/downloadfile", [ "id" => $tasks[0]['id'], "name" => $file['name'] ]);
print_r("DOWNLOADED LEN OF IMAGE FILE: ".strlen($image));
print_r($task_entry);
$task_string = zerof_request("/v2/tasks/".$task_entry['id'], null);
$task = json_decode(html_entity_decode($task_string), true);
print "TASK:\n";
print_r($task);
foreach($task['views'][0]['files'] AS $file)
{
$image = false;
$retry = 0;
while($image === false && $retry < 2)
{
$image = zerof_request("/v2/tasks/downloadfile", [ "id" => $task_entry['id'], "name" => $file['name'] ], 30);
$retry++;
}
print_r("DOWNLOADED LEN OF IMAGE FILE: ".strlen($image));
print "\n";
if(strlen($image) < 100)
{
print "IMAGE ???? ".$image."\n\n";
}
if($image)
{
array_push($images, $image);
}
}
print "\n";
if(strlen($image) < 100)
{
print "IMAGE ???? ".$image."\n\n";
}
if($image)
{
array_push($images, $image);
}
break;
}
print "\n";
print "\n";
}
print "zerof_get_images | ".$task_uid." END\n";
print "\n";
return $images;