Ver Fonte

correction after MR

Vincent há 1 ano atrás
pai
commit
4c4d0c9e52

+ 8 - 0
.env.ci

@@ -44,4 +44,12 @@ API_LEG_BASE_URL=https://api.ci.opentalent.fr/api
 
 ###> url v1 ###
 PUBLIC_API_LEG_BASE_URL=https://api.ci.opentalent.fr
+###
+
+###> api v2 ###
+API_BASE_URL=https://ap2i.ci.opentalent.fr/api
+###< api v1 ###
+
+###> url v2 ###
+PUBLIC_API_BASE_URL=https://ap2i.ci.opentalent.fr
 ###

+ 8 - 0
.env.docker

@@ -18,6 +18,14 @@ API_LEG_BASE_URL=http://nginx/
 PUBLIC_API_LEG_BASE_URL=https://local.api.opentalent.fr
 ###
 
+###> api v2 ###
+API_BASE_URL=http://nginx_new/
+###< api v1 ###
+
+###> url v2 ###
+PUBLIC_API_BASE_URL=https://local.ap2i.opentalent.fr
+###
+
 ###> BlackFire configuration ###
 BLACKFIRE_CLIENT_ID=988fcba8-552d-48df-a9c2-035c76535b69
 BLACKFIRE_CLIENT_TOKEN=8cfbeb263d044da9678dc2612531504da3790c308da7448e35724a5da91c136f

+ 9 - 1
.env.prod

@@ -10,12 +10,20 @@ CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)$
 
 ###> api v1 ###
 API_LEG_BASE_URL=https://api.opentalent.fr/api
-###< files management ###
+###
 
 ###> url v1 ###
 PUBLIC_API_LEG_BASE_URL=https://api.opentalent.fr/api
 ###
 
+###> api v2 ###
+API_BASE_URL=https://ap2i.opentalent.fr/api
+###< api v1 ###
+
+###> url v2 ###
+PUBLIC_API_BASE_URL=https://ap2i.opentalent.fr/api
+###
+
 ###> BlackFire configuration ###
 BLACKFIRE_CLIENT_ID=988fcba8-552d-48df-a9c2-035c76535b69
 BLACKFIRE_CLIENT_TOKEN=8cfbeb263d044da9678dc2612531504da3790c308da7448e35724a5da91c136f

+ 8 - 0
.env.staging

@@ -17,6 +17,14 @@ API_LEG_BASE_URL=https://none
 PUBLIC_API_LEG_BASE_URL=https://none
 ###
 
+###> api v2 ###
+API_BASE_URL=https://none
+###< api v1 ###
+
+###> url v2 ###
+PUBLIC_API_BASE_URL=https://none
+###
+
 ###> elasticsearch ###
 ELASTICSEARCH_HOST=es
 ELASTICSEARCH_PORT=9200

+ 8 - 0
.env.test

@@ -18,6 +18,14 @@ API_LEG_BASE_URL=https://api.test.opentalent.fr/api
 PUBLIC_API_LEG_BASE_URL=https://api.test.opentalent.fr/api
 ###
 
+###> api v2 ###
+API_BASE_URL=https://ap2i.test.opentalent.fr/api
+###< api v1 ###
+
+###> url v2 ###
+PUBLIC_API_BASE_URL=https://ap2i.test.opentalent.fr/api
+###
+
 ###> typo3 client ###
 TYPO3_BASE_URI=http://test.opentalent.fr/ohcluses
 ###< typo3 client ###

+ 1 - 1
config/packages/knp_gaufrette.yaml

@@ -4,7 +4,7 @@ knp_gaufrette:
   adapters:
     storage:
       local:
-        directory: '%kernel.project_dir%/files/storage'
+        directory: '%kernel.project_dir%/storage'
         create: true
   filesystems:
     storage:

+ 1 - 0
config/services.yaml

@@ -21,6 +21,7 @@ services:
             $removeProcessor: '@api_platform.doctrine.orm.state.remove_processor'
             $opentalentNoReplyEmailAddress: 'noreply@opentalent.fr'
             $legacyBaseUrl: '%env(PUBLIC_API_LEG_BASE_URL)%'
+            $baseUrl: '%env(PUBLIC_API_BASE_URL)%'
 
     # makes classes in src/ available to be used as services
     # this creates a service per class whose id is the fully-qualified class name

+ 1 - 2
src/Service/Export/BaseExporter.php

@@ -10,8 +10,7 @@ use App\Repository\Access\AccessRepository;
 use App\Repository\Core\FileRepository;
 use App\Service\Export\Model\ExportModelInterface;
 use App\Service\File\FileManager;
-use App\Service\File\Manager\DocumentManager;
-use App\Service\File\Utils\FileUtils;
+use App\Service\Utils\FileUtils;
 use App\Service\ServiceIterator\EncoderIterator;
 use App\Service\Utils\StringsUtils;
 use Doctrine\ORM\EntityManagerInterface;

+ 3 - 0
src/Service/File/Factory/ImageFactory.php

@@ -9,6 +9,9 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager;
 use Liip\ImagineBundle\Imagine\Data\DataManager;
 use Liip\ImagineBundle\Imagine\Filter\FilterManager;
 
+/**
+ * Utilise Liip Imagine Bundle afin de créer les images selon une configuration et les stock dans un cache
+ */
 class ImageFactory
 {
     public function __construct(

+ 1 - 1
src/Service/File/Storage/ApiLegacyStorage.php

@@ -43,7 +43,7 @@ class ApiLegacyStorage implements FileStorageInterface
      */
     public function getImageUrl(File $file, string $size, bool $relativePath): string{
         $url = sprintf('api/files/%s/download/%s?relativePath=1', $file->getId(), $size);
-        return sprintf('%s%s', $this->legacyBaseUrl, $this->apiLegacyRequestService->getContent($url));
+        return UrlBuilder::concat($this->legacyBaseUrl, [$this->apiLegacyRequestService->getContent($url)], []);
     }
 
     /**

+ 5 - 4
src/Service/File/Storage/LocalStorage.php

@@ -8,11 +8,12 @@ use App\Entity\Core\File;
 use App\Entity\Organization\Organization;
 use App\Entity\Person\Person;
 use App\Enum\Core\FileHostEnum;
+use App\Enum\Core\FileSizeEnum;
 use App\Enum\Core\FileStatusEnum;
 use App\Enum\Core\FileTypeEnum;
 use App\Repository\Access\AccessRepository;
 use App\Service\File\Factory\ImageFactory;
-use App\Service\File\Utils\FileUtils;
+use App\Service\Utils\FileUtils;
 use App\Service\Utils\Path;
 use App\Service\Utils\UrlBuilder;
 use App\Service\Utils\Uuid;
@@ -123,14 +124,14 @@ class LocalStorage implements FileStorageInterface
      */
     private function getFilterFromSizeAndConfig(string $size, bool $configExist): string{
         switch($size){
-            case 'sm':
+            case FileSizeEnum::SM :
                 $filter = $configExist ? self::CROP_SM : self::SM_FOLDER;
                 break;
-            case 'md':
+            case FileSizeEnum::MD :
             default:
                 $filter = $configExist ? self::CROP_MD : self::MD_FOLDER;
                 break;
-            case 'lg':
+            case FileSizeEnum::LG :
                 $filter = $configExist ? self::CROP_LG : self::LG_FOLDER;
                 break;
         }

+ 3 - 2
src/Service/File/Utils/FileUtils.php → src/Service/Utils/FileUtils.php

@@ -2,7 +2,7 @@
 
 declare(strict_types=1);
 
-namespace App\Service\File\Utils;
+namespace App\Service\Utils;
 
 use App\Entity\Core\File;
 use Mimey\MimeTypes;
@@ -46,6 +46,7 @@ class FileUtils
      */
     public function isImage(File $file): bool
     {
-        return boolval(preg_match('#^image#', $file->getMimeType()));
+        $mimetype = $file->getMimeType() ?: $this->guessMimeTypeFromFilename($file->getName());
+        return boolval(preg_match('#^image#', $mimetype));
     }
 }

+ 9 - 11
src/Service/Utils/UrlBuilder.php

@@ -4,7 +4,6 @@ declare(strict_types=1);
 namespace App\Service\Utils;
 
 use Symfony\Component\Routing\Generator\UrlGenerator;
-use Symfony\Component\Routing\RequestContext;
 
 /**
  * Building url utilities
@@ -12,20 +11,20 @@ use Symfony\Component\Routing\RequestContext;
 class UrlBuilder
 {
 
-    public function __construct(private RequestContext $requestContext){}
+    public function __construct(private string $baseUrl){}
 
     /**
      * Concatenate a base url and a path
      *
-     * @param string $url The base url
-     * @param string $path The following path
+     * @param string $base The base url
+     * @param array $tails La suite de l'URL sous forme de tableau
      * @return string
      */
     public static function concatPath(string $base, array $tails): string
     {
         $url = $base;
         foreach ($tails as $tail){
-            $url = preg_replace('/^\/|\/$/i', '', $url) . '/' . preg_replace('/^\/?|\/?$/i', '', strval($tail));
+            $url = trim($url) . '/' . trim(strval($tail));
         }
 
         return $url;
@@ -77,14 +76,14 @@ class UrlBuilder
      * Build an url
      *
      * @param string $url The base url
-     * @param string $path A path to append (can be an empty string)
+     * @param array $tails la suite de l'url sous forme de tableau
      * @param list<string> $parameters A list of parameters (can be an empty array)
      * @param bool $preprendHttps Should the 'https://' be prepended if missing
      * @return string
      */
-    public static function concat(string $url, string $path, array $parameters, bool $preprendHttps = false): string
+    public static function concat(string $url, array $tails, array $parameters, bool $preprendHttps = false): string
     {
-        $url = self::concatParameters(self::concatPath($url, $path), $parameters);
+        $url = self::concatParameters(self::concatPath($url, $tails), $parameters);
         if ($preprendHttps) {
             $url = self::prependHttps($url);
         }
@@ -97,8 +96,7 @@ class UrlBuilder
      * @return string
      */
     public function getRelativeUrl(string $path): string{
-        $baseUrl = sprintf('%s://%s/', $this->requestContext->getScheme(), $this->requestContext->getHost() );
-        return UrlGenerator::getRelativePath($baseUrl, $path);
+        return UrlGenerator::getRelativePath($this->baseUrl, $path);
     }
 
     /**
@@ -107,6 +105,6 @@ class UrlBuilder
      * @return string
      */
     public function getAbsoluteUrl(string $path): string{
-        return sprintf('%s://%s/%s', $this->requestContext->getScheme(), $this->requestContext->getHost(), $path );
+        return self::concat($this->baseUrl, [$path], []);
     }
 }

+ 1 - 1
src/State/Provider/Core/ImageProvider.php

@@ -10,7 +10,7 @@ use App\Enum\Core\FileStatusEnum;
 use App\Repository\Core\FileRepository;
 use App\Service\File\Exception\FileNotFoundException;
 use App\Service\File\FileManager;
-use App\Service\File\Utils\FileUtils;
+use App\Service\Utils\FileUtils;
 use RuntimeException;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Response;