2020-04-05 08:59:55 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-04-05 08:59:55 +00:00
|
|
|
*/
|
|
|
|
namespace OC\Preview;
|
|
|
|
|
2020-04-05 09:01:40 +00:00
|
|
|
use OC\Archive\ZIP;
|
2020-04-05 08:59:55 +00:00
|
|
|
use OCP\Files\File;
|
|
|
|
use OCP\IImage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts a preview from files that embed them in an ZIP archive
|
|
|
|
*/
|
|
|
|
abstract class Bundled extends ProviderV2 {
|
2022-02-24 13:42:55 +00:00
|
|
|
protected function extractThumbnail(File $file, string $path): ?IImage {
|
2022-02-14 22:48:14 +00:00
|
|
|
if ($file->getSize() === 0) {
|
2022-02-03 07:56:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-05 08:59:55 +00:00
|
|
|
$sourceTmp = \OC::$server->getTempManager()->getTemporaryFile();
|
|
|
|
$targetTmp = \OC::$server->getTempManager()->getTemporaryFile();
|
2022-02-24 13:55:57 +00:00
|
|
|
$this->tmpFiles[] = $sourceTmp;
|
|
|
|
$this->tmpFiles[] = $targetTmp;
|
2020-04-05 08:59:55 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$content = $file->fopen('r');
|
|
|
|
file_put_contents($sourceTmp, $content);
|
|
|
|
|
2020-04-05 09:01:40 +00:00
|
|
|
$zip = new ZIP($sourceTmp);
|
2020-04-05 08:59:55 +00:00
|
|
|
$zip->extractFile($path, $targetTmp);
|
|
|
|
|
2022-06-02 00:37:36 +00:00
|
|
|
$image = new \OCP\Image();
|
2020-04-05 08:59:55 +00:00
|
|
|
$image->loadFromFile($targetTmp);
|
|
|
|
$image->fixOrientation();
|
|
|
|
|
|
|
|
return $image;
|
2022-02-28 14:40:33 +00:00
|
|
|
} catch (\Throwable $e) {
|
2020-04-05 08:59:55 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|