diff --git a/vas/rest/class/vmlib/files/Files_common.class.inc b/vas/rest/class/vmlib/files/Files_common.class.inc index cd8431f26e52d596761db98e7663b24c5130cc6e..4e2ee795f0d83814e81a58c580273765c14671b4 100644 --- a/vas/rest/class/vmlib/files/Files_common.class.inc +++ b/vas/rest/class/vmlib/files/Files_common.class.inc @@ -17,9 +17,8 @@ abstract class Files_common { *@return Retourne une chaine. */ public function extension($sPath) { - $aTemp = explode(".", $sString); + $aTemp = explode(".", $sPath); $sString = strtolower($aTemp[count($aTemp) - 1]); - return $sString; } diff --git a/vas/rest/class/vmlib/files/Files_manager.class.inc b/vas/rest/class/vmlib/files/Files_manager.class.inc index 0f8e79dc60719e1fe652e3f2e4b7815bab08d7c6..923aa8af60e107d269851a4030f81a43b1525d7d 100644 --- a/vas/rest/class/vmlib/files/Files_manager.class.inc +++ b/vas/rest/class/vmlib/files/Files_manager.class.inc @@ -99,16 +99,12 @@ class Files_manager{ return $sErrorMsg; } - $aTemp = explode("/", $sServerPath); - - $sFileName = end($aTemp); + $sFileName = $this->getFileName($sServerPath); $sFileExtension = $this->extension($sFileName); - if (!in_array($sFileExtension, $aForbiddenExtension)) { //Teste si le fichier correspont au format voulu. $bAllowUpload = false; $sFormat = ""; - if (in_array($sFileType, array_keys($aExtension))){ if (in_array($sFileExtension, $aExtension[$sFileType])) { $bAllowUpload = true; 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);