mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
store encrypted content
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\AsyncUpload\Driver\LocalStorage\StoredObjectManager;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Controller to deal with local storage operation.
|
||||
*/
|
||||
final readonly class StoredObjectContentToLocalStorageController
|
||||
{
|
||||
public function __construct(
|
||||
private StoredObjectManager $storedObjectManager,
|
||||
) {}
|
||||
|
||||
#[Route('/public/stored-object/post', name: 'chill_docstore_storedobject_post', methods: ['POST'])]
|
||||
public function postContent(Request $request): Response
|
||||
{
|
||||
$prefix = $request->query->get('prefix', '');
|
||||
|
||||
if ('' === $prefix) {
|
||||
throw new BadRequestHttpException('prefix parameter is missing');
|
||||
}
|
||||
|
||||
$keyFiles = $request->files->keys();
|
||||
|
||||
foreach ($keyFiles as $keyFile) {
|
||||
/** @var UploadedFile $file */
|
||||
$file = $request->files->get($keyFile);
|
||||
$this->storedObjectManager->writeContent($keyFile, $file->getContent());
|
||||
}
|
||||
|
||||
return new Response(status: Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
#[Route('/public/stored-object/operate', name: 'chill_docstore_stored_object_operate', methods: ['GET', 'HEAD'])]
|
||||
public function contentOperate(Request $request): Response
|
||||
{
|
||||
$objectName = $request->query->get('object_name', '');
|
||||
|
||||
if ('' === $objectName) {
|
||||
throw new BadRequestHttpException('object name parameter is missing');
|
||||
}
|
||||
|
||||
if (!$this->storedObjectManager->existsContent($objectName)) {
|
||||
throw new NotFoundHttpException('object does not exists on disk');
|
||||
}
|
||||
|
||||
return match ($request->getMethod()) {
|
||||
'GET' => new Response($this->storedObjectManager->readContent($objectName)),
|
||||
'HEAD' => new Response(''),
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user