123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- declare(strict_types=1);
- namespace OC\Preview;
- use OCP\Files\File;
- use OCP\Files\FileInfo;
- use OCP\IImage;
- use OCP\Preview\IProviderV2;
- abstract class ProviderV2 implements IProviderV2 {
-
- protected $options;
-
- protected $tmpFiles = [];
-
- public function __construct(array $options = []) {
- $this->options = $options;
- }
-
- abstract public function getMimeType(): string ;
-
- public function isAvailable(FileInfo $file): bool {
- return true;
- }
-
- abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;
- protected function useTempFile(File $file): bool {
- return $file->isEncrypted() || !$file->getStorage()->isLocal();
- }
-
- protected function getLocalFile(File $file, ?int $maxSize = null) {
- if ($this->useTempFile($file)) {
- $absPath = \OC::$server->getTempManager()->getTemporaryFile();
- $content = $file->fopen('r');
- if ($maxSize) {
- $content = stream_get_contents($content, $maxSize);
- }
- file_put_contents($absPath, $content);
- $this->tmpFiles[] = $absPath;
- return $absPath;
- } else {
- $path = $file->getStorage()->getLocalFile($file->getInternalPath());
- if (is_string($path)) {
- return $path;
- } else {
- return false;
- }
- }
- }
-
- protected function cleanTmpFiles(): void {
- foreach ($this->tmpFiles as $tmpFile) {
- unlink($tmpFile);
- }
- $this->tmpFiles = [];
- }
- }
|