use cache for minio

This commit is contained in:
Arnaud Fornerot 2022-08-31 12:05:06 +02:00
parent d539a2a740
commit 50322de0ff
1 changed files with 22 additions and 34 deletions

View File

@ -30,7 +30,7 @@ class MinioService
$this->initBucket();
}
public function download(string $file, string $filename, bool $returnFile = false)
public function download(string $file, string $filename, bool $usecache = true)
{
// On s'assure que le repertoire temporaire de destination existe bien
$fs = new Filesystem();
@ -38,6 +38,7 @@ class MinioService
$fs->mkdir($tmpdir."/".dirname($filename));
// Approche repassant par le serveur d'appel
if(!$usecache||!$fs->exists($tmpdir.'/'.$filename)) {
try {
$result = $this->client->getObject([
'Bucket' => $this->minioBucket,
@ -58,22 +59,9 @@ class MinioService
\Sentry\captureException($e);
throw new Exception(self::ERR_UNAVAILABLE);
}
if ($returnFile) {
return $tmpdir.'/'.$filename;
} else {
//Suppression de la copie locale
unlink($tmpdir.'/'.$filename);
$res = new Response($result['Body'], 200);
$res->headers->set('Content-Type', 'application/pdf');
$res->headers->set('Content-Description', 'File Transfer');
$res->headers->set('Content-Disposition', 'attachment; filename='.$filename);
$res->headers->set('Expires', '0');
$res->headers->set('Cache-Control', 'must-revalidate');
$res->headers->set('Pragma', 'public');
return $res;
}
return $tmpdir.'/'.$filename;
}
public function upload($file, $filename, $deleteSource = false)