From e29ebe84ecc09e57b0f69dcd5792bbeea9410454 Mon Sep 17 00:00:00 2001 From: Eric Wasson <229096365+Eric-Wasson@users.noreply.github.com> Date: Fri, 20 Feb 2026 14:18:29 +0100 Subject: [PATCH 1/2] Removed taskExtraDetails endpoint --- src/api/v2/index.php | 1 - .../apiv2/helper/taskExtraDetails.routes.php | 112 ------------------ src/inc/apiv2/model/tasks.routes.php | 39 ++++++ 3 files changed, 39 insertions(+), 113 deletions(-) delete mode 100644 src/inc/apiv2/helper/taskExtraDetails.routes.php diff --git a/src/api/v2/index.php b/src/api/v2/index.php index 6bb341b0d..017c73a7b 100644 --- a/src/api/v2/index.php +++ b/src/api/v2/index.php @@ -392,7 +392,6 @@ public static function addCORSheaders(Request $request, $response) { require_once($helperDir . "/resetUserPassword.routes.php"); require_once($helperDir . "/searchHashes.routes.php"); require_once($helperDir . "/setUserPassword.routes.php"); -require_once($helperDir . "/taskExtraDetails.routes.php"); require_once($helperDir . "/unassignAgent.routes.php"); $app->run(); diff --git a/src/inc/apiv2/helper/taskExtraDetails.routes.php b/src/inc/apiv2/helper/taskExtraDetails.routes.php deleted file mode 100644 index a939f606f..000000000 --- a/src/inc/apiv2/helper/taskExtraDetails.routes.php +++ /dev/null @@ -1,112 +0,0 @@ -preCommon($request); - - $taskId = $request->getQueryParams()['task']; - if ($taskId === null) { - throw new HttpErrorException("No task query param has been provided"); - } - $taskId = intval($taskId); - if ($taskId === 0) { - throw new HttpErrorException("No valid integer provided as task"); - } - $task = Factory::getTaskFactory()->get($taskId); - if ($task === null) { - throw new HttpErrorException("No task found for provided task ID"); - } - - $qF = new QueryFilter(Chunk::TASK_ID, $taskId, "="); - $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); - $currentSpeed = 0; - $cProgress = 0; - foreach ($chunks as $chunk) { - $cProgress += $chunk->getCheckpoint() - $chunk->getSkip(); - if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { - $currentSpeed += $chunk->getSpeed(); - } - } - - $timeChunks = $chunks; - usort($timeChunks, "Util::compareChunksTime"); - $timeSpent = 0; - $current = 0; - foreach ($timeChunks as $c) { - if ($c->getDispatchTime() > $current) { - $timeSpent += $c->getSolveTime() - $c->getDispatchTime(); - $current = $c->getSolveTime(); - } - else if ($c->getSolveTime() > $current) { - $timeSpent += $c->getSolveTime() - $current; - $current = $c->getSolveTime(); - } - } - $keyspace = $task->getKeyspace(); - $estimatedTime = ($keyspace > 0 && $cProgress > 0) ? round($timeSpent / ($cProgress / $keyspace) - $timeSpent) : 0; - $responseObject = [ - "estimatedTime" => $estimatedTime, - "timeSpent" => $timeSpent, - "currentSpeed" => $currentSpeed, - "cprogress" => $cProgress, - ]; - - return self::getMetaResponse($responseObject, $request, $response); - } - - public function actionPost($data): object|array|null { - throw new HttpError("TaskExtraDetails has no POST"); - } - - static public function register($app): void { - $baseUri = TaskExtraDetailsHelper::getBaseUri(); - - /* Allow CORS preflight requests */ - $app->options($baseUri, function (Request $request, Response $response): Response { - return $response; - }); - $app->get($baseUri, "TaskExtraDetailsHelper:handleGet"); - } - - /** - * getAccessGroups is different because it returns via another function - */ - public static function getResponse(): array|string|null { - return null; - } -} - -use Slim\App; -/** @var App $app */ -TaskExtraDetailsHelper::register($app); diff --git a/src/inc/apiv2/model/tasks.routes.php b/src/inc/apiv2/model/tasks.routes.php index c2ed6bb35..1079c906c 100644 --- a/src/inc/apiv2/model/tasks.routes.php +++ b/src/inc/apiv2/model/tasks.routes.php @@ -211,6 +211,45 @@ static function aggregateData(object $object, array &$included_data = [], ?array $aggregatedData["status"] = $status; } + + if (is_null($aggregateFieldsets) || in_array("taskExtraDetails", $aggregateFieldsets['task'])) { + $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + + $currentSpeed = 0; + $cProgress = 0; + + foreach ($chunks as $chunk) { + $cProgress += $chunk->getCheckpoint() - $chunk->getSkip(); + if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { + $currentSpeed += $chunk->getSpeed(); + } + } + + $timeChunks = $chunks; + usort($timeChunks, "Util::compareChunksTime"); + $timeSpent = 0; + $current = 0; + + foreach ($timeChunks as $c) { + if ($c->getDispatchTime() > $current) { + $timeSpent += $c->getSolveTime() - $c->getDispatchTime(); + $current = $c->getSolveTime(); + } + else if ($c->getSolveTime() > $current) { + $timeSpent += $c->getSolveTime() - $current; + $current = $c->getSolveTime(); + } + } + + $keyspace = $object->getKeyspace(); + $estimatedTime = ($keyspace > 0 && $cProgress > 0) ? round($timeSpent / ($cProgress / $keyspace) - $timeSpent) : 0; + + $aggregatedData["estimatedTime"] = $estimatedTime; + $aggregatedData["timeSpent"] = $timeSpent; + $aggregatedData["currentSpeed"] = $currentSpeed; + $aggregatedData["cprogress"] = $cProgress; + } } return $aggregatedData; From f4ab9adf9baadfb77f8718e91b17dc6a36f6bd40 Mon Sep 17 00:00:00 2001 From: s3inlc Date: Mon, 2 Mar 2026 14:57:06 +0100 Subject: [PATCH 2/2] added classpath to usort() argument --- src/inc/apiv2/model/TaskAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index 403fd114a..9bc429ef8 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -235,7 +235,7 @@ static function aggregateData(object $object, array &$included_data = [], ?array } $timeChunks = $chunks; - usort($timeChunks, "Util::compareChunksTime"); + usort($timeChunks, "\Hashtopolis\inc\Util::compareChunksTime"); $timeSpent = 0; $current = 0;