diff --git a/lib/Preview/Office.php b/lib/Preview/Office.php index a38b78503a..9b6457b917 100644 --- a/lib/Preview/Office.php +++ b/lib/Preview/Office.php @@ -7,7 +7,9 @@ use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Capabilities; +use OCA\Richdocuments\Service\RemoteOptionsService; use OCP\Files\File; +use OCP\Files\FileInfo; use OCP\Http\Client\IClientService; use OCP\IImage; use OCP\Image; @@ -15,15 +17,20 @@ use Psr\Log\LoggerInterface; abstract class Office implements IProviderV2 { - private array $capabilities = []; - - public function __construct(private IClientService $clientService, private AppConfig $config, Capabilities $capabilities, private LoggerInterface $logger) { - $this->capabilitites = $capabilities->getCapabilities()['richdocuments'] ?? []; + private array $capabilities; + + public function __construct( + private IClientService $clientService, + private AppConfig $config, + Capabilities $capabilities, + private LoggerInterface $logger, + ) { + $this->capabilities = $capabilities->getCapabilities()['richdocuments'] ?? []; } - public function isAvailable(\OCP\Files\FileInfo $file): bool { - if (isset($this->capabilitites['collabora']['convert-to']['available'])) { - return (bool)$this->capabilitites['collabora']['convert-to']['available']; + public function isAvailable(FileInfo $file): bool { + if (isset($this->capabilities['collabora']['convert-to']['available'])) { + return (bool)$this->capabilities['collabora']['convert-to']['available']; } return false; } @@ -45,11 +52,9 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { } $client = $this->clientService->newClient(); - $options = [ - 'timeout' => 25, - // FIXME: Can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream - 'expect' => false, - ]; + $options = RemoteOptionsService::getDefaultOptions(); + // FIXME: can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream + $options['expect'] = false; if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') { $options['verify'] = false; diff --git a/lib/Service/CachedRequestService.php b/lib/Service/CachedRequestService.php index 87f616d9cf..9c71247ac9 100644 --- a/lib/Service/CachedRequestService.php +++ b/lib/Service/CachedRequestService.php @@ -19,7 +19,6 @@ use Psr\Log\LoggerInterface; abstract class CachedRequestService { - public function __construct( private IClientService $clientService, private ICacheFactory $cacheFactory, @@ -91,12 +90,7 @@ public function resetCache(): void { } protected function getDefaultRequestOptions(): array { - $options = [ - 'timeout' => 5, - 'nextcloud' => [ - 'allow_local_address' => true - ] - ]; + $options = RemoteOptionsService::getDefaultOptions(); if ($this->appConfig->getValueString('richdocuments', 'disable_certificate_verification') === 'yes') { $options['verify'] = false; diff --git a/lib/Service/RemoteOptionsService.php b/lib/Service/RemoteOptionsService.php new file mode 100644 index 0000000000..0c54ca8d82 --- /dev/null +++ b/lib/Service/RemoteOptionsService.php @@ -0,0 +1,17 @@ + $timeout, + 'nextcloud' => [ + 'allow_local_address' => true, + ] + ]; + } + +} diff --git a/lib/Service/RemoteService.php b/lib/Service/RemoteService.php index 50e6428e5f..e94d54fba5 100644 --- a/lib/Service/RemoteService.php +++ b/lib/Service/RemoteService.php @@ -13,9 +13,6 @@ use Psr\Log\LoggerInterface; class RemoteService { - - public const REMOTE_TIMEOUT_DEFAULT = 25; - public function __construct( private AppConfig $appConfig, private IClientService $clientService, @@ -69,12 +66,10 @@ private function getRequestOptionsForFile(File $file, ?string $target = null): a $stream = $file->fopen('rb'); } - $options = [ - 'timeout' => self::REMOTE_TIMEOUT_DEFAULT, - 'multipart' => [ - ['name' => $file->getName(), 'contents' => $stream], - ['name' => 'target', 'contents' => $target] - ] + $options = RemoteOptionsService::getDefaultOptions(25); + $options['multipart'] = [ + ['name' => $file->getName(), 'contents' => $stream], + ['name' => 'target', 'contents' => $target] ]; if ($this->appConfig->getDisableCertificateValidation()) {