-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCancelDownloadAction.php
More file actions
41 lines (35 loc) · 1.25 KB
/
CancelDownloadAction.php
File metadata and controls
41 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Stochastix\Domain\Data\Controller;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
#[AsController]
#[Route('/api/data/download/{jobId}', name: 'stochastix_api_data_cancel_download', methods: ['DELETE'])]
class CancelDownloadAction extends AbstractController
{
public function __construct(
#[Autowire(service: 'stochastix.download.cancel.cache')]
private readonly CacheItemPoolInterface $cache,
) {
}
/**
* @throws InvalidArgumentException
*/
public function __invoke(string $jobId): JsonResponse
{
$cacheKey = 'download.cancel.' . $jobId;
$item = $this->cache->getItem($cacheKey);
$item->set(true);
$item->expiresAfter(3600);
$this->cache->save($item);
return $this->json(
['status' => 'cancellation_requested', 'jobId' => $jobId],
Response::HTTP_ACCEPTED
);
}
}