Olivier Massot 3 gadi atpakaļ
vecāks
revīzija
0eaea28481

+ 13 - 4
src/DataProvider/DownloadRequestDataProvider.php

@@ -37,17 +37,26 @@ final class DownloadRequestDataProvider implements ItemDataProviderInterface, Re
         if ($file->getStatus() !== FileStatusEnum::READY()->getValue()) {
             throw new \RuntimeException("File " . $id . " has " . $file->getStatus() . " status; abort.");
         }
+        if ($file->getHost() === 'api') {
+            throw new \RuntimeException('Incorrect host for file ' . $id . '');
+        }
 
         $content = $this->storage->read($file);
 
         // @see https://symfony.com/doc/current/components/http_foundation.html#serving-files
         $response = new Response($content);
 
-        $disposition = HeaderUtils::makeDisposition(
-            HeaderUtils::DISPOSITION_ATTACHMENT,
-            $file->getName()
+        $response->headers->set('Charset', 'UTF-8');
+        $response->headers->set('Access-Control-Expose-Headers', 'Content-Disposition');
+
+        if (!empty($file->getMimeType())) {
+            $response->headers->set('Content-Type', $file->getMimeType());
+        }
+
+        $response->headers->set(
+            'Content-Disposition',
+            HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $file->getName())
         );
-        $response->headers->set('Content-Disposition', $disposition);
 
         return $response;
     }

+ 16 - 0
src/Entity/Core/File.php

@@ -539,6 +539,22 @@ class File
         return $this;
     }
 
+    /**
+     * @return string|null
+     */
+    public function getHost(): ?string
+    {
+        return $this->host;
+    }
+
+    /**
+     * @param string|null $host
+     */
+    public function setHost(?string $host): void
+    {
+        $this->host = $host;
+    }
+
     public function getOrganizationLogos(): Collection
     {
         return $this->organizationLogos;

+ 0 - 4
src/Service/Export/BaseExporter.php

@@ -73,10 +73,6 @@ abstract class BaseExporter implements ExporterInterface
         // Génère le html à partir du template et du service
         $html = $this->render($model);
 
-        $f = fopen("test.html", "w+");
-        fwrite($f, $html);
-        fclose($f);
-
         // Encode le html au format voulu
         $content = $this->encode($html, $exportRequest->getFormat());