|
|
@@ -1,49 +1,83 @@
|
|
|
<?php
|
|
|
-declare (strict_types=1);
|
|
|
+
|
|
|
+declare(strict_types=1);
|
|
|
|
|
|
namespace App\ApiResources\Core\File;
|
|
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
|
-use ApiPlatform\Metadata\Get;
|
|
|
+use ApiPlatform\Metadata\Post;
|
|
|
+use ApiPlatform\Metadata\Put;
|
|
|
+use App\Enum\Core\FileTypeEnum;
|
|
|
use App\State\Processor\Core\UploadRequestProcessor;
|
|
|
use App\State\Provider\Core\DownloadRequestProvider;
|
|
|
+use Ramsey\Uuid\Uuid;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
- * A request for a file from the LocalStorage
|
|
|
+ * A request to upload the given content to a File
|
|
|
*/
|
|
|
#[ApiResource(
|
|
|
operations: [
|
|
|
new Post(
|
|
|
- uriTemplate: '/upload/{fileId}',
|
|
|
- requirements: ['fileId' => '\\d+'],
|
|
|
- security: 'is_granted("ROLE_FILE")',
|
|
|
- processor: UploadRequestProcessor::class
|
|
|
- ),
|
|
|
- new Put(
|
|
|
- uriTemplate: '/upload/{fileId}',
|
|
|
- requirements: ['fileId' => '\\d+'],
|
|
|
+ uriTemplate: '/upload',
|
|
|
+ requirements: ['id' => '\\d+'],
|
|
|
security: 'is_granted("ROLE_FILE")',
|
|
|
processor: UploadRequestProcessor::class
|
|
|
- ),
|
|
|
- new Post(
|
|
|
- uriTemplate: '/internal/download/{fileId}',
|
|
|
- requirements: ['fileId' => '\\d+'],
|
|
|
- processor: UploadRequestProcessor::class
|
|
|
- ),
|
|
|
- new Put(
|
|
|
- uriTemplate: '/internal/download/{fileId}',
|
|
|
- requirements: ['fileId' => '\\d+'],
|
|
|
- processor: UploadRequestProcessor::class
|
|
|
)
|
|
|
]
|
|
|
)]
|
|
|
class UploadRequest
|
|
|
{
|
|
|
- private int $fileId;
|
|
|
+ /**
|
|
|
+ * Only because id is required
|
|
|
+ * @var int | null
|
|
|
+ */
|
|
|
+ #[ApiProperty(identifier: true)]
|
|
|
+ private ?int $fileId = null;
|
|
|
|
|
|
+ /**
|
|
|
+ * Le nom du fichier
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ private string $filename;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The content of the uploaded file
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
private string $content;
|
|
|
|
|
|
+ /**
|
|
|
+ * Si vrai, le propriétaire du fichier ne sera pas l'utilisateur en cours, mais l'organisation à laquelle il
|
|
|
+ * appartient.
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ private bool $organizationOwned = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Le type de fichier uploadé, si connu
|
|
|
+ * @var FileTypeEnum
|
|
|
+ */
|
|
|
+ private FileTypeEnum $type;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Visibilité du fichier
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ private string $visibility = 'NOBODY';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Type mime (il sera déduit automatiquement du nom du fichier s'il n'est pas fourni ici)
|
|
|
+ * @var string|null
|
|
|
+ */
|
|
|
+ private ?string $mimeType = null;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->type = FileTypeEnum::NONE();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return int
|
|
|
*/
|
|
|
@@ -51,21 +85,121 @@ class UploadRequest
|
|
|
{
|
|
|
return $this->fileId;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @param int $fileId
|
|
|
+ * @param int $id
|
|
|
+ * @return self
|
|
|
*/
|
|
|
- public function setFileId(int $fileId) : void
|
|
|
+ public function setFileId(int $id) : self
|
|
|
{
|
|
|
- $this->fileId = $fileId;
|
|
|
+ $this->fileId = $id;
|
|
|
+ return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
public function getContent(): string
|
|
|
{
|
|
|
return $this->content;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param string $content
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function setContent(string $content): void
|
|
|
{
|
|
|
$this->content = $content;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function isOrganizationOwned(): bool
|
|
|
+ {
|
|
|
+ return $this->organizationOwned;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param bool $organizationOwned
|
|
|
+ * @return self
|
|
|
+ */
|
|
|
+ public function setOrganizationOwned(bool $organizationOwned): self
|
|
|
+ {
|
|
|
+ $this->organizationOwned = $organizationOwned;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getFilename(): string
|
|
|
+ {
|
|
|
+ return $this->filename;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $filename
|
|
|
+ * @return self
|
|
|
+ */
|
|
|
+ public function setFilename(string $filename): self
|
|
|
+ {
|
|
|
+ $this->filename = $filename;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return FileTypeEnum
|
|
|
+ */
|
|
|
+ public function getType(): FileTypeEnum
|
|
|
+ {
|
|
|
+ return $this->type;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param FileTypeEnum $type
|
|
|
+ * @return self
|
|
|
+ */
|
|
|
+ public function setType(FileTypeEnum $type): self
|
|
|
+ {
|
|
|
+ $this->type = $type;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getVisibility(): string
|
|
|
+ {
|
|
|
+ return $this->visibility;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $visibility
|
|
|
+ * @return self
|
|
|
+ */
|
|
|
+ public function setVisibility(string $visibility): self
|
|
|
+ {
|
|
|
+ $this->visibility = $visibility;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string|null
|
|
|
+ */
|
|
|
+ public function getMimeType(): ?string
|
|
|
+ {
|
|
|
+ return $this->mimeType;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string|null $mimeType
|
|
|
+ * @return self
|
|
|
+ */
|
|
|
+ public function setMimeType(?string $mimeType): self
|
|
|
+ {
|
|
|
+ $this->mimeType = $mimeType;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
}
|