-
Notifications
You must be signed in to change notification settings - Fork 246
Added helper endpoint to get the cracks of a task #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <?php | ||
|
|
||
| use DBA\Chunk; | ||
| use DBA\ContainFilter; | ||
| use JetBrains\PhpStorm\NoReturn; | ||
| use Psr\Http\Message\ResponseInterface as Response; | ||
| use Psr\Http\Message\ServerRequestInterface as Request; | ||
| use DBA\Factory; | ||
| use DBA\Hash; | ||
| use DBA\QueryFilter; | ||
| use DBA\Task; | ||
| use Middlewares\Utils\HttpErrorException; | ||
|
|
||
| require_once(dirname(__FILE__) . "/../common/AbstractHelperAPI.class.php"); | ||
|
|
||
| class getCracksOfTaskHelper extends AbstractHelperAPI { | ||
jessevz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static function getBaseUri(): string { | ||
| return "/api/v2/helper/getCracksOfTask"; | ||
| } | ||
|
|
||
| public static function getAvailableMethods(): array { | ||
| return ['GET']; | ||
| } | ||
|
|
||
| public function getRequiredPermissions(string $method): array { | ||
| return [Hash::PERM_READ, Task::PERM_READ]; | ||
jessevz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public static function getResponse(): null { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| #[NoReturn] public function actionPost(array $data): object|array|null { | ||
| assert(False, "getCracksOfTask has no POST"); | ||
| } | ||
|
|
||
| /** | ||
| * Description of get params for swagger. | ||
| */ | ||
| public function getParamsSwagger(): array { | ||
| return [ | ||
| [ | ||
| "in" => "query", | ||
| "name" => "task", | ||
| "schema" => [ | ||
| "type" => "integer", | ||
| "format" => "int32" | ||
| ], | ||
| "required" => true, | ||
| "example" => 1, | ||
| "description" => "The ID of the task." | ||
| ] | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Endpoint to get the cracked hashes of a certain task | ||
| * @param Request $request | ||
| * @param Response $response | ||
| * @return Response | ||
| * @throws HttpErrorException | ||
| */ | ||
| public function handleGet(Request $request, Response $response): Response { | ||
| $this->preCommon($request); | ||
| $task = Factory::getTaskFactory()->get($_GET['task']); | ||
jessevz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ($task == null) { | ||
| throw new HttpError("No task has been found with provided task id"); | ||
| } | ||
| $hashlists = Util::checkSuperHashlist(Factory::getHashlistFactory()->get(Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId())->getHashlistId())); | ||
| if ($hashlists[0]->getFormat() == DHashlistFormat::PLAIN) { | ||
| $hashFactory = Factory::getHashFactory(); | ||
| } | ||
| else { | ||
| $hashFactory = Factory::getHashBinaryFactory(); | ||
| } | ||
| $qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "="); | ||
| $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); | ||
| $chunkIds = array(); | ||
| foreach ($chunks as $chunk) { | ||
| $chunkIds[] = $chunk->getId(); | ||
| } | ||
| $queryFilters[] = new ContainFilter(Hash::CHUNK_ID, $chunkIds); | ||
| $queryFilters[] = new QueryFilter(Hash::IS_CRACKED, 1, "="); | ||
| $hashes = $hashFactory->filter([Factory::FILTER => $queryFilters]); | ||
| $converted = []; | ||
|
|
||
| foreach ($hashes as $hash) { | ||
| $converted[] = self::obj2Resource($hash); | ||
| } | ||
| $ret = self::createJsonResponse(data: $converted); | ||
|
|
||
| $body = $response->getBody(); | ||
| $body->write($this->ret2json($ret)); | ||
|
|
||
| return $response->withStatus(200) | ||
| ->withHeader("Content-Type", 'application/vnd.api+json;'); | ||
| } | ||
|
|
||
| static public function register($app): void { | ||
| $baseUri = getCracksOfTaskHelper::getBaseUri(); | ||
|
|
||
| /* Allow CORS preflight requests */ | ||
| $app->options($baseUri, function (Request $request, Response $response): Response { | ||
| return $response; | ||
| }); | ||
| $app->get($baseUri, "getCracksOfTaskHelper:handleGet"); | ||
| } | ||
| } | ||
|
|
||
| getCracksOfTaskHelper::register($app); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.