2019-10-10 02:13:04 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-10-10 02:13:04 +00:00
|
|
|
namespace App\Controller\Api\Stations\Files;
|
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
use App\Entity;
|
2021-03-31 16:42:24 +00:00
|
|
|
use App\Flysystem\StationFilesystems;
|
2019-10-10 02:13:04 +00:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
|
|
|
class DownloadAction
|
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
ServerRequest $request,
|
2021-03-31 16:42:24 +00:00
|
|
|
Response $response
|
2019-10-10 02:13:04 +00:00
|
|
|
): ResponseInterface {
|
|
|
|
set_time_limit(600);
|
|
|
|
|
|
|
|
$station = $request->getStation();
|
2021-06-08 06:40:49 +00:00
|
|
|
$fsMedia = (new StationFilesystems($station))->getMediaFilesystem();
|
2020-09-14 03:26:26 +00:00
|
|
|
|
2020-12-22 21:40:33 +00:00
|
|
|
$path = $request->getParam('file');
|
2020-09-14 03:26:26 +00:00
|
|
|
|
2021-03-31 16:42:24 +00:00
|
|
|
if (!$fsMedia->fileExists($path)) {
|
2020-09-14 03:26:26 +00:00
|
|
|
return $response->withStatus(404)
|
2021-07-19 05:53:45 +00:00
|
|
|
->withJson(Entity\Api\Error::notFound());
|
2020-09-14 03:26:26 +00:00
|
|
|
}
|
2019-10-10 02:13:04 +00:00
|
|
|
|
2021-04-05 23:31:29 +00:00
|
|
|
return $response->streamFilesystemFile($fsMedia, $path);
|
2019-10-10 02:13:04 +00:00
|
|
|
}
|
2020-10-14 22:19:31 +00:00
|
|
|
}
|