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;
|
|
|
|
|
|
|
|
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;
|
2021-03-31 16:42:24 +00:00
|
|
|
use SebastianBergmann\CodeCoverage\DirectoryCouldNotBeCreatedException;
|
2019-10-10 02:13:04 +00:00
|
|
|
|
|
|
|
class MakeDirectoryAction
|
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
ServerRequest $request,
|
2021-03-31 16:42:24 +00:00
|
|
|
Response $response
|
2019-10-10 02:13:04 +00:00
|
|
|
): ResponseInterface {
|
2020-11-23 06:38:49 +00:00
|
|
|
$currentDir = $request->getParam('currentDirectory', '');
|
|
|
|
$newDirName = $request->getParam('name', '');
|
2019-10-10 02:13:04 +00:00
|
|
|
|
2020-11-23 06:38:49 +00:00
|
|
|
if (empty($newDirName)) {
|
|
|
|
return $response->withStatus(400)
|
|
|
|
->withJson(new Entity\Api\Error(400, __('No directory specified')));
|
|
|
|
}
|
2019-10-10 02:13:04 +00:00
|
|
|
|
|
|
|
$station = $request->getStation();
|
2021-03-31 16:42:24 +00:00
|
|
|
|
2021-06-08 06:40:49 +00:00
|
|
|
$fsMedia = (new StationFilesystems($station))->getMediaFilesystem();
|
2019-10-10 02:13:04 +00:00
|
|
|
|
2020-11-23 06:38:49 +00:00
|
|
|
$newDir = $currentDir . '/' . $newDirName;
|
2021-03-31 16:42:24 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$fsMedia->createDirectory($newDir);
|
|
|
|
} catch (DirectoryCouldNotBeCreatedException $e) {
|
|
|
|
return $response->withStatus(400)
|
|
|
|
->withJson(new Entity\Api\Error(400, $e->getMessage()));
|
2019-10-10 02:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $response->withJson(new Entity\Api\Status());
|
|
|
|
}
|
2020-10-14 22:19:31 +00:00
|
|
|
}
|