diff --git a/vas/rest/ws/vitis/Vitis.class.inc b/vas/rest/ws/vitis/Vitis.class.inc index e9a9451d683fc7881562b03a6e810aa781de4f51..8a5c4da59651c0c09d1dd64ad8a91f9d2926a22a 100644 --- a/vas/rest/ws/vitis/Vitis.class.inc +++ b/vas/rest/ws/vitis/Vitis.class.inc @@ -2,6 +2,7 @@ require_once(__DIR__ . "/../../class/vitis_lib/DbClass.class.inc"); require_once ("aws_sdk/aws-autoloader.php"); +require_once 'vmlib/files/Files_manager.class.inc'; /** * \file vitis.class.inc @@ -45,6 +46,10 @@ class Vitis extends DbClass { * Connection object(connect to the database, get user groups and privileges) */ public $oConnection; + /** + * File Manager objet (allow to interact with file) + */ + public $oFilesManager; /** * construct @@ -59,6 +64,7 @@ class Vitis extends DbClass { $this->aValues = $aValues; $this->aPath = $aPath; $this->aProperties = $properties; + $this->oFilesManager = new Files_manager($properties); if (empty($oConnection)) { $this->oConnection = new Connection($this->aValues, $this->aProperties); } else { @@ -250,71 +256,21 @@ class Vitis extends DbClass { // Vérifie si il y a des fichiers à renvoyer if ($sVitisObjectName != "") { - $sDataUrl = $this->aProperties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp(); - - if($this->aProperties['filesystem' == 's3']){ - // use HEAD on s3 Object - // traitement du bucket et de ses sous-dossiers - $sBucket = $this->aProperties['fileS3UploaderBucket']; - $sPrefix = ""; - - if (strpos($sBucket, "/") > -1){ - $aBucket = explode("/", $sBucket ); - $sBucket = $aBucket[0]; - $sPrefix = implode("/", array_slice($aBucket, 1)); - } - // Création du client S3 - $s3 = new Aws\S3\S3Client(array( - 'version'=>'latest', - 'region'=> $this->aProperties['fileS3UploaderRegion'], - 'profile'=> $this->aProperties['fileS3UploaderProfil'], - 'debug' => false - )); - - $sListPrefix = $sPrefix . "/ws_data/".$sVitisModuleName.'/' . $sVitisObjectName . '/'; - - if (!empty($sVitisPathComplement)){ - $sListPrefix .= $sVitisPathComplement . '/'; - } - - $sListPrefix .= $oObject->aFields[$sIdField]; - - try{ - $aList = $s3->listObjectsV2(array( - 'Bucket' => $sBucket, - 'Prefix' => $sListPrefix - )); - - - - if ($aList["KeyCount"] > 0){ - foreach ($aList["Contents"] as $aObject){ - $aPath = explode("/", $aObject["Key"]); - $sObjectField = $aPath[count($aPath) - 2]; - - $sFileUrl = str_replace("[KEY]", $aObject["Key"], $sDataUrl); - $oObject->aFields[$sObjectField] = str_replace("[ETAG]", str_replace('"', '', $aObject["ETag"]), $sFileUrl); - } - } - }catch(Aws\S3\Exception\S3Exception $e){ - writeToErrorLog($e->getMessage()); - } - } else { - // check dans ws_data - $sDataDir = $this->aProperties['ws_data_dir'] . '/'.$sVitisModuleName.'/' . $sVitisObjectName . '/' . $sVitisPathComplement . '/' . $oObject->aFields[$sIdField]; - if (is_dir($sDataDir)) { - // Remplace le nom du fichier par son url - foreach ($oObject->aFields as $key => $value) { - if (is_dir($sDataDir . "/" . $key)) { - $sKey = "ws_data/".$sVitisModuleName.'/' . $sVitisObjectName . '/' . $sVitisPathComplement . '/' . $oObject->aFields[$sIdField]. "/" . $key . "/" . $value; - $sEtag = sha1(file_get_contents($sDataDir . "/" . $key . "/" . $value ), false); - - $sFileUrl = str_replace("[KEY]", $sKey, $sDataUrl); - $oObject->aFields[$key] = str_replace("[ETAG]", $sEtag, $sFileUrl); - } - } - } + // check dans ws_data + $sDataDir = $this->aProperties['ws_data_dir'] . '/'.$sVitisModuleName.'/' . $sVitisObjectName; + if(!empty($sVitisPathComplement)){ + $sDataDir .= '/' . $sVitisPathComplement; + } + $sDataDir .= '/' . $oObject->aFields[$sIdField]; + + if ($this->oFilesManager->oFileInterface->is_dir($sDataDir)) { + // Remplace le nom du fichier par son url + foreach ($oObject->aFields as $key => $value) { + if ($this->oFilesManager->oFileInterface->is_dir($sDataDir . "/" . $key)) { + $oObject->aFields[$key] = $this->oFilesManager->oFileInterface->getProxyPassUrl($sDataDir . "/" . $key . "/" . $value); + } + } } } array_push($this->aObjects, $oObject);