芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/cloud.pulsehost.co.uk/vendor/afterlogic/dav/lib/DAV/FS/S3/Personal/Root.php
getConfig('BucketPrefix'); $sBucket = \strtolower($sBucketPrefix . \str_replace([' ', '.'], '-', Server::getTenantName())); $this->client = $this->getS3Client(); static $bDoesBucketExist = null; $buckets = $this->client->listBuckets(); foreach ($buckets['Buckets'] as $bucket) { if ($bucket['Name'] === $sBucket) { $bDoesBucketExist = true; break; } } if (!$bDoesBucketExist) { $this->createBucket($this->client, $sBucket); } if (empty($sPrefix)) { $sPrefix = $this->getUser(); } parent::__construct('/' . $sPrefix, $sBucket, $this->client, $this->storage); } protected function getS3Client() { static $client = false; if (!$client) { $oModule = S3Filestorage\Module::getInstance(); $sRegion = $oModule->getConfig('Region'); $sAccessKey = $oModule->getConfig('AccessKey'); $sSecretKey = $oModule->getConfig('SecretKey'); $credentials = new Credentials($sAccessKey, $sSecretKey); $aOptions = [ 'region' => $sRegion, 'version' => 'latest', 'credentials' => $credentials, 'use_path_style_endpoint' => $oModule->getConfig('UsePathStyleEndpoint') ]; $endpoint = $oModule->getConfig('Host'); if (!empty($endpoint)) { $aOptions['endpoint'] = 'https://' . $endpoint; } $client = new S3Client($aOptions); } return $client; } protected function createBucket($client, $sBucket) { $res = $client->createBucket([ 'Bucket' => $sBucket ]); try { $client->putBucketCors([ 'Bucket' => $sBucket, 'CORSConfiguration' => [ 'CORSRules' => [ [ 'AllowedHeaders' => [ '*', ], 'AllowedMethods' => [ 'GET', 'PUT', 'POST', 'DELETE', 'HEAD' ], 'AllowedOrigins' => [ (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] ], 'MaxAgeSeconds' => 0, ], ], ], // 'ContentMD5' => '', ]); } catch (\Exception $ex) { Api::LogException($ex); } } public function getName() { return $this->storage; } public function setName($name) { throw new \Sabre\DAV\Exception\Forbidden(); } public function delete() { throw new \Sabre\DAV\Exception\Forbidden(); } protected function getUsedSize($sUserPublicId) { $iSize = 0; if (!empty($sUserPublicId)) { $searchResult = $this->client->getPaginator('ListObjectsV2', [ 'Bucket' => $this->bucket, 'Prefix' => $sUserPublicId . '/' ])->search('Contents[?Size.to_number(@) != `0`].Size.to_number(@)'); $iSize = array_sum( iterator_to_array($searchResult) ); } return $iSize; } public function getQuotaInfo() { $sUserSpaceLimitInMb = -1; $oUser = \Aurora\Modules\Core\Module::getInstance()->getUserByPublicId($this->getUser()); if ($oUser) { $sUserSpaceLimitInMb = $oUser->getExtendedProp('Files::UserSpaceLimitMb') * 1024 * 1024; } return [ (int) $this->getUsedSize($this->UserPublicId), (int) $sUserSpaceLimitInMb ]; } }