UploadRequest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\ApiResources\Core\File;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use App\Enum\Core\FileTypeEnum;
  9. use App\State\Processor\Core\UploadRequestProcessor;
  10. use App\State\Provider\Core\DownloadRequestProvider;
  11. use Ramsey\Uuid\Uuid;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * A request to upload the given content to a File
  15. */
  16. #[ApiResource(
  17. operations: [
  18. new Post(
  19. uriTemplate: '/upload',
  20. requirements: ['id' => '\\d+'],
  21. security: 'is_granted("ROLE_FILE")',
  22. processor: UploadRequestProcessor::class
  23. )
  24. ]
  25. )]
  26. class UploadRequest
  27. {
  28. /**
  29. * @var int | null
  30. */
  31. #[ApiProperty(identifier: true)]
  32. private ?int $fileId = null;
  33. /**
  34. * Le nom du fichier
  35. * @var string
  36. */
  37. private string $filename;
  38. /**
  39. * Le contenu du fichier uploadé encodé au format Base64
  40. * @var string
  41. */
  42. private string $content;
  43. /**
  44. * Si vrai, le propriétaire du fichier ne sera pas l'utilisateur en cours, mais l'organisation à laquelle il
  45. * appartient.
  46. * @var bool
  47. */
  48. private bool $organizationOwned = false;
  49. /**
  50. * Le type de fichier uploadé, si connu
  51. * @var string
  52. */
  53. #[Assert\Choice(callback: [FileTypeEnum::class, 'toArray'])]
  54. private string $type = "NONE";
  55. /**
  56. * Visibilité du fichier
  57. * @var string
  58. */
  59. private string $visibility = 'NOBODY';
  60. /**
  61. * Type mime (il sera déduit automatiquement du nom du fichier s'il n'est pas fourni ici)
  62. * @var string|null
  63. */
  64. private ?string $mimeType = null;
  65. /**
  66. * Configuration du fichier (par exemple le cropping d'une image)
  67. * @var string
  68. */
  69. private ?string $config = null;
  70. public function __construct()
  71. {
  72. $this->type = FileTypeEnum::NONE()->getValue();
  73. }
  74. /**
  75. * @return int
  76. */
  77. public function getFileId() : int
  78. {
  79. return $this->fileId;
  80. }
  81. /**
  82. * @param int $id
  83. * @return self
  84. */
  85. public function setFileId(int $id) : self
  86. {
  87. $this->fileId = $id;
  88. return $this;
  89. }
  90. /**
  91. * @return string
  92. */
  93. public function getContent(): string
  94. {
  95. return $this->content;
  96. }
  97. /**
  98. * @param string $content
  99. * @return void
  100. */
  101. public function setContent(string $content): void
  102. {
  103. $this->content = $content;
  104. }
  105. /**
  106. * @return bool
  107. */
  108. public function isOrganizationOwned(): bool
  109. {
  110. return $this->organizationOwned;
  111. }
  112. /**
  113. * @param bool $organizationOwned
  114. * @return self
  115. */
  116. public function setOrganizationOwned(bool $organizationOwned): self
  117. {
  118. $this->organizationOwned = $organizationOwned;
  119. return $this;
  120. }
  121. /**
  122. * @return string
  123. */
  124. public function getFilename(): string
  125. {
  126. return $this->filename;
  127. }
  128. /**
  129. * @param string $filename
  130. * @return self
  131. */
  132. public function setFilename(string $filename): self
  133. {
  134. $this->filename = $filename;
  135. return $this;
  136. }
  137. /**
  138. * @return string
  139. */
  140. public function getType(): string
  141. {
  142. return $this->type;
  143. }
  144. /**
  145. * @param string $type
  146. * @return self
  147. */
  148. public function setType(string $type): self
  149. {
  150. $this->type = $type;
  151. return $this;
  152. }
  153. /**
  154. * @return string
  155. */
  156. public function getVisibility(): string
  157. {
  158. return $this->visibility;
  159. }
  160. /**
  161. * @param string $visibility
  162. * @return self
  163. */
  164. public function setVisibility(string $visibility): self
  165. {
  166. $this->visibility = $visibility;
  167. return $this;
  168. }
  169. /**
  170. * @return string|null
  171. */
  172. public function getMimeType(): ?string
  173. {
  174. return $this->mimeType;
  175. }
  176. /**
  177. * @param string|null $mimeType
  178. * @return self
  179. */
  180. public function setMimeType(?string $mimeType): self
  181. {
  182. $this->mimeType = $mimeType;
  183. return $this;
  184. }
  185. /**
  186. * @return string|null
  187. */
  188. public function getConfig(): ?string
  189. {
  190. return $this->config;
  191. }
  192. /**
  193. * @param string|null $config
  194. * @return self
  195. */
  196. public function setConfig(?string $config): self
  197. {
  198. $this->config = $config;
  199. return $this;
  200. }
  201. }