|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2019 Robin Appelman <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @license GNU AGPL version 3 or any later version |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
10
|
|
|
* License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OC\Preview; |
|
23
|
|
|
|
|
24
|
|
|
use OC\Files\View; |
|
25
|
|
|
use OCP\Files\File; |
|
26
|
|
|
use OCP\Files\FileInfo; |
|
27
|
|
|
use OCP\IImage; |
|
28
|
|
|
use OCP\Preview\IProvider; |
|
29
|
|
|
use OCP\Preview\IProviderV2; |
|
30
|
|
|
|
|
31
|
|
|
class ProviderV1Adapter implements IProviderV2 { |
|
32
|
|
|
private $providerV1; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(IProvider $providerV1) { |
|
35
|
|
|
$this->providerV1 = $providerV1; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getMimeType(): string { |
|
39
|
|
|
return $this->providerV1->getMimeType(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function isAvailable(FileInfo $file): bool { |
|
43
|
|
|
return $this->isAvailable($file); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
|
47
|
|
|
list($view, $path) = $this->getViewAndPath($file); |
|
48
|
|
|
$thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view); |
|
49
|
|
|
return $thumbnail === false ? null: $thumbnail; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function getViewAndPath(File $file) { |
|
53
|
|
|
$view = new View($file->getParent()->getPath()); |
|
54
|
|
|
$path = $file->getName(); |
|
55
|
|
|
|
|
56
|
|
|
return [$view, $path]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|