Exemplo n.º 1
0
 /**
  * @param FileData $fileData
  * @return null|EditSession
  * @throws \Bitrix\Main\NotImplementedException
  */
 protected function addCreateEditSessionByCurrentUser(FileData $fileData)
 {
     return EditSession::add(array('USER_ID' => $this->getUser()->getId(), 'OWNER_ID' => $this->getUser()->getId(), 'IS_EXCLUSIVE' => 1, 'SERVICE' => $this->documentHandler->getCode(), 'SERVICE_FILE_ID' => $fileData->getId(), 'SERVICE_FILE_LINK' => $fileData->getLinkInService()), $this->errorCollection);
 }
Exemplo n.º 2
0
 /**
  * Gets a file's metadata by ID
  * @param FileData $fileData
  * @return array|null
  */
 private function getFileMetadataInternal(FileData $fileData)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) {
         return null;
     }
     $accessToken = $this->getAccessToken();
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $http->setHeader('Authorization', "Bearer {$accessToken}");
     if ($http->get(self::API_URL_V2 . '/files/' . $fileData->getId()) === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_GET_METADATA)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $file = Json::decode($http->getResult());
     if ($file === null) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     return $file;
 }
Exemplo n.º 3
0
 /**
  * Download part of file from cloud service by FileData::id, put contents in FileData::src
  * @param FileData $fileData
  * @param          $startRange
  * @param          $chunkSize
  * @return FileData|null
  */
 public function downloadPartFile(FileData $fileData, $startRange, $chunkSize)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('id', 'src'))) {
         return null;
     }
     $accessToken = $this->getAccessToken();
     @set_time_limit(0);
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Authorization', "Bearer {$accessToken}");
     $endRange = $startRange + $chunkSize - 1;
     $http->setHeader('Range', "bytes={$startRange}-{$endRange}");
     if ($http->download(self::API_URL_V2 . "/files/{$fileData->getId()}/content", $fileData->getSrc()) === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_DOWNLOAD_FILE)));
         return null;
     }
     return $fileData;
 }
Exemplo n.º 4
0
 /**
  * Check success view file in service.
  * @param FileData $fileData
  * @return bool
  */
 public function checkViewFile(FileData $fileData)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) {
         return null;
     }
     if (!ExternalLink::isValidValueForField('HASH', $fileData->getId(), $this->errorCollection)) {
         return false;
     }
     /** @var ExternalLink $extLinkModel */
     $extLinkModel = ExternalLink::load(array('=HASH' => $fileData->getId()));
     if (!$extLinkModel) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_GOOGLE_VIEWER_HANDLER_ERROR_COULD_NOT_FIND_EXT_LINK'), self::ERROR_COULD_NOT_FIND_EXT_LINK)));
         return null;
     }
     return (bool) $extLinkModel->getDownloadCount();
 }
Exemplo n.º 5
0
 public function getDownloadUrl(FileData $fileData)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) {
         return null;
     }
     $fileId = $this->getForApiDecodedId($fileData->getId());
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $http->setHeader('Authorization', "OAuth {$this->getAccessToken()}");
     if ($http->get(self::API_URL_V1 . "/resources/download?path={$fileId}") === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_GET_METADATA)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $downloadData = Json::decode($http->getResult());
     if ($downloadData === null || empty($downloadData['href'])) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     return $downloadData['href'];
 }
Exemplo n.º 6
0
 protected function getSharedEmbedLink(FileData $fileData)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) {
         return null;
     }
     $accessToken = $this->getAccessToken();
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $accessToken = urlencode($accessToken);
     if ($http->get("https://apis.live.net/v5.0/{$fileData->getId()}/embed?access_token={$accessToken}") === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_SHARED_EMBED_LINK)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $finalOutput = Json::decode($http->getResult());
     if ($finalOutput === null) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     if (!preg_match('%src="(.*)"%iuU', $finalOutput['embed_html'], $m)) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_ONE_DRIVE_HANDLER_ERROR_COULD_NOT_FIND_EMBED_LINK'), self::ERROR_COULD_NOT_FIND_EMBED_LINK)));
         return null;
     }
     return $m[1];
 }