Skip to content

Commit

Permalink
request to remote if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Antipkin-A committed Oct 7, 2022
1 parent e1a21af commit 5728682
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
26 changes: 2 additions & 24 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;

use OCA\Files_Sharing\External\Storage as SharingExternalStorage;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\DocumentService;
Expand Down Expand Up @@ -535,7 +533,7 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan

$prevIsForcesave = KeyManager::wasForcesave($fileId);

if ($this->isFederatedOperation($file)) {
if (RemoteInstance::isRemoteFile($file)) {
$isLock = RemoteInstance::lockRemoteKey($file, $isForcesave, null);
if ($isForcesave && !$isLock) {
break;
Expand All @@ -549,7 +547,7 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
return $file->putContent($newData);
});

if ($this->isFederatedOperation($file)) {
if (RemoteInstance::isRemoteFile($file)) {
if ($isForcesave) {
RemoteInstance::lockRemoteKey($file, false, $isForcesave);
}
Expand Down Expand Up @@ -722,26 +720,6 @@ private function getFileByToken($fileId, $shareToken, $version = 0) {
return [$file, null];
}

/**
* Check of federated capable
*
* @param File $file - file
*
* @return bool
*/
private function isFederatedOperation($file) {
$storage = $file->getStorage();

$alive = false;
$isFederated = $storage->instanceOfStorage(SharingExternalStorage::class);
if (!$isFederated) {
return false;
}

$alive = RemoteInstance::healthCheck($storage->getRemote());
return $alive;
}

/**
* Getting share by token
*
Expand Down
4 changes: 1 addition & 3 deletions controller/federationcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

use OC\OCS\Result;

use OCA\Files_Sharing\External\Storage as SharingExternalStorage;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\DocumentService;
use OCA\Onlyoffice\FileUtility;
Expand Down Expand Up @@ -138,7 +136,7 @@ public function keylock($shareToken, $path, $lock, $fs) {

$fileId = $file->getId();

if ($file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
if (RemoteInstance::isRemoteFile($file)) {
$isLock = RemoteInstance::lockRemoteKey($file, $lock, $fs);
if (!$isLock) {
return new Result(["error" => "Failed request"]);
Expand Down
4 changes: 1 addition & 3 deletions lib/fileutility.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use OCP\ISession;
use OCP\Share\IManager;

use OCA\Files_Sharing\External\Storage as SharingExternalStorage;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Version;
use OCA\Onlyoffice\KeyManager;
Expand Down Expand Up @@ -223,7 +221,7 @@ public function getKey($file, $origin = false) {
$fileId = $file->getId();

if ($origin
&& $file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
&& RemoteInstance::isRemoteFile($file)) {

try {
$key = RemoteInstance::getRemoteKey($file);
Expand Down
22 changes: 22 additions & 0 deletions lib/remoteinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

use OCP\Files\File;

use OCA\Files_Sharing\External\Storage as SharingExternalStorage;

/**
* Remote instance manager
*
Expand Down Expand Up @@ -245,4 +247,24 @@ public static function lockRemoteKey($file, $lock, $fs) {
return false;
}
}

/**
* Check of federated capable
*
* @param File $file - file
*
* @return bool
*/
public static function isRemoteFile($file) {
$storage = $file->getStorage();

$alive = false;
$isFederated = $storage->instanceOfStorage(SharingExternalStorage::class);
if (!$isFederated) {
return false;
}

$alive = RemoteInstance::healthCheck($storage->getRemote());
return $alive;
}
}

0 comments on commit 5728682

Please sign in to comment.