|
10 | 10 | namespace OCA\Richdocuments\Conversion; |
11 | 11 |
|
12 | 12 | use OCA\Richdocuments\Service\RemoteService; |
| 13 | +use OCA\Richdocuments\Service\SecureViewService; |
13 | 14 | use OCP\Files\Conversion\ConversionMimeProvider; |
14 | 15 | use OCP\Files\Conversion\IConversionProvider; |
15 | 16 | use OCP\Files\File; |
| 17 | +use OCP\Files\NotFoundException; |
16 | 18 | use OCP\IL10N; |
17 | 19 | use OCP\L10N\IFactory; |
18 | 20 | use Psr\Log\LoggerInterface; |
@@ -53,6 +55,7 @@ public function __construct( |
53 | 55 | private RemoteService $remoteService, |
54 | 56 | private LoggerInterface $logger, |
55 | 57 | IFactory $l10nFactory, |
| 58 | + private SecureViewService $secureViewService, |
56 | 59 | ) { |
57 | 60 | $this->l10n = $l10nFactory->get('richdocuments'); |
58 | 61 | } |
@@ -144,6 +147,24 @@ public function convertFile(File $file, string $targetMimeType): mixed { |
144 | 147 | )); |
145 | 148 | } |
146 | 149 |
|
| 150 | + if ($this->secureViewService->isEnabled()) { |
| 151 | + try { |
| 152 | + $secured = $this->secureViewService->shouldSecure( |
| 153 | + $file->getInternalPath(), |
| 154 | + $file->getStorage(), |
| 155 | + false, |
| 156 | + ); |
| 157 | + } catch (NotFoundException $e) { |
| 158 | + $this->logger->warning('Could not determine Secure View status for conversion target', ['exception' => $e]); |
| 159 | + throw new \Exception($this->l10n->t('Conversion is unavailable for this file.')); |
| 160 | + } |
| 161 | + if ($secured) { |
| 162 | + throw new \Exception($this->l10n->t( |
| 163 | + 'Conversion is blocked because the file is protected by Secure View.' |
| 164 | + )); |
| 165 | + } |
| 166 | + } |
| 167 | + |
147 | 168 | return $this->remoteService->convertFileTo($file, $targetFileExtension); |
148 | 169 | } |
149 | 170 |
|
|
0 commit comments