Merge pull request #20319 from nextcloud/enh/noid/embedded-previews
Use embedded previews of ZIP-like files
This commit is contained in:
commit
37146c9b0f
|
@ -989,7 +989,6 @@ $CONFIG = [
|
|||
* - OC\Preview\MSOffice2003
|
||||
* - OC\Preview\MSOffice2007
|
||||
* - OC\Preview\MSOfficeDoc
|
||||
* - OC\Preview\OpenDocument
|
||||
* - OC\Preview\PDF
|
||||
* - OC\Preview\Photoshop
|
||||
* - OC\Preview\Postscript
|
||||
|
@ -998,14 +997,6 @@ $CONFIG = [
|
|||
* - OC\Preview\TIFF
|
||||
* - OC\Preview\Font
|
||||
*
|
||||
* The following providers are not available in Microsoft Windows:
|
||||
*
|
||||
* - OC\Preview\Movie
|
||||
* - OC\Preview\MSOfficeDoc
|
||||
* - OC\Preview\MSOffice2003
|
||||
* - OC\Preview\MSOffice2007
|
||||
* - OC\Preview\OpenDocument
|
||||
* - OC\Preview\StarOffice
|
||||
*
|
||||
* Defaults to the following providers:
|
||||
*
|
||||
|
@ -1018,6 +1009,8 @@ $CONFIG = [
|
|||
* - OC\Preview\PNG
|
||||
* - OC\Preview\TXT
|
||||
* - OC\Preview\XBitmap
|
||||
* - OC\Preview\OpenDocument
|
||||
* - OC\Preview\Krita
|
||||
*/
|
||||
'enabledPreviewProviders' => [
|
||||
'OC\Preview\PNG',
|
||||
|
@ -1028,7 +1021,9 @@ $CONFIG = [
|
|||
'OC\Preview\XBitmap',
|
||||
'OC\Preview\MP3',
|
||||
'OC\Preview\TXT',
|
||||
'OC\Preview\MarkDown'
|
||||
'OC\Preview\MarkDown',
|
||||
'OC\Preview\OpenDocument',
|
||||
'OC\Preview\Krita',
|
||||
],
|
||||
|
||||
/**
|
||||
|
|
|
@ -1124,6 +1124,7 @@ return array(
|
|||
'OC\\Preview\\BMP' => $baseDir . '/lib/private/Preview/BMP.php',
|
||||
'OC\\Preview\\BackgroundCleanupJob' => $baseDir . '/lib/private/Preview/BackgroundCleanupJob.php',
|
||||
'OC\\Preview\\Bitmap' => $baseDir . '/lib/private/Preview/Bitmap.php',
|
||||
'OC\\Preview\\Bundled' => $baseDir . '/lib/private/Preview/Bundled.php',
|
||||
'OC\\Preview\\Font' => $baseDir . '/lib/private/Preview/Font.php',
|
||||
'OC\\Preview\\GIF' => $baseDir . '/lib/private/Preview/GIF.php',
|
||||
'OC\\Preview\\Generator' => $baseDir . '/lib/private/Preview/Generator.php',
|
||||
|
@ -1132,6 +1133,7 @@ return array(
|
|||
'OC\\Preview\\Illustrator' => $baseDir . '/lib/private/Preview/Illustrator.php',
|
||||
'OC\\Preview\\Image' => $baseDir . '/lib/private/Preview/Image.php',
|
||||
'OC\\Preview\\JPEG' => $baseDir . '/lib/private/Preview/JPEG.php',
|
||||
'OC\\Preview\\Krita' => $baseDir . '/lib/private/Preview/Krita.php',
|
||||
'OC\\Preview\\MP3' => $baseDir . '/lib/private/Preview/MP3.php',
|
||||
'OC\\Preview\\MSOffice2003' => $baseDir . '/lib/private/Preview/MSOffice2003.php',
|
||||
'OC\\Preview\\MSOffice2007' => $baseDir . '/lib/private/Preview/MSOffice2007.php',
|
||||
|
|
|
@ -1153,6 +1153,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OC\\Preview\\BMP' => __DIR__ . '/../../..' . '/lib/private/Preview/BMP.php',
|
||||
'OC\\Preview\\BackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Preview/BackgroundCleanupJob.php',
|
||||
'OC\\Preview\\Bitmap' => __DIR__ . '/../../..' . '/lib/private/Preview/Bitmap.php',
|
||||
'OC\\Preview\\Bundled' => __DIR__ . '/../../..' . '/lib/private/Preview/Bundled.php',
|
||||
'OC\\Preview\\Font' => __DIR__ . '/../../..' . '/lib/private/Preview/Font.php',
|
||||
'OC\\Preview\\GIF' => __DIR__ . '/../../..' . '/lib/private/Preview/GIF.php',
|
||||
'OC\\Preview\\Generator' => __DIR__ . '/../../..' . '/lib/private/Preview/Generator.php',
|
||||
|
@ -1161,6 +1162,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OC\\Preview\\Illustrator' => __DIR__ . '/../../..' . '/lib/private/Preview/Illustrator.php',
|
||||
'OC\\Preview\\Image' => __DIR__ . '/../../..' . '/lib/private/Preview/Image.php',
|
||||
'OC\\Preview\\JPEG' => __DIR__ . '/../../..' . '/lib/private/Preview/JPEG.php',
|
||||
'OC\\Preview\\Krita' => __DIR__ . '/../../..' . '/lib/private/Preview/Krita.php',
|
||||
'OC\\Preview\\MP3' => __DIR__ . '/../../..' . '/lib/private/Preview/MP3.php',
|
||||
'OC\\Preview\\MSOffice2003' => __DIR__ . '/../../..' . '/lib/private/Preview/MSOffice2003.php',
|
||||
'OC\\Preview\\MSOffice2007' => __DIR__ . '/../../..' . '/lib/private/Preview/MSOffice2007.php',
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\Preview;
|
||||
|
||||
use OC\Archive\ZIP;
|
||||
use OCP\Files\File;
|
||||
use OCP\IImage;
|
||||
|
||||
/**
|
||||
* Extracts a preview from files that embed them in an ZIP archive
|
||||
*/
|
||||
abstract class Bundled extends ProviderV2 {
|
||||
|
||||
protected function extractThumbnail(File $file, $path): ?IImage {
|
||||
$sourceTmp = \OC::$server->getTempManager()->getTemporaryFile();
|
||||
$targetTmp = \OC::$server->getTempManager()->getTemporaryFile();
|
||||
|
||||
try {
|
||||
$content = $file->fopen('r');
|
||||
file_put_contents($sourceTmp, $content);
|
||||
|
||||
$zip = new ZIP($sourceTmp);
|
||||
$zip->extractFile($path, $targetTmp);
|
||||
|
||||
$image = new \OC_Image();
|
||||
$image->loadFromFile($targetTmp);
|
||||
$image->fixOrientation();
|
||||
|
||||
return $image;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\Preview;
|
||||
|
||||
use OCP\Files\File;
|
||||
use OCP\IImage;
|
||||
|
||||
class Krita extends Bundled {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMimeType(): string {
|
||||
return '/application\/x-krita/';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
|
||||
$image = $this->extractThumbnail($file, 'mergedimage.png');
|
||||
if ($image->valid()) {
|
||||
return $image;
|
||||
}
|
||||
$image = $this->extractThumbnail($file, 'preview.png');
|
||||
if ($image->valid()) {
|
||||
return $image;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -25,11 +25,26 @@
|
|||
namespace OC\Preview;
|
||||
|
||||
//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
|
||||
class OpenDocument extends Office {
|
||||
use OCP\Files\File;
|
||||
use OCP\IImage;
|
||||
|
||||
class OpenDocument extends Bundled {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMimeType(): string {
|
||||
return '/application\/vnd.oasis.opendocument.*/';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
|
||||
$image = $this->extractThumbnail($file, 'Thumbnails/thumbnail.png');
|
||||
if ($image->valid()) {
|
||||
return $image;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,13 +293,15 @@ class PreviewManager implements IPreview {
|
|||
Preview\GIF::class,
|
||||
Preview\BMP::class,
|
||||
Preview\HEIC::class,
|
||||
Preview\XBitmap::class
|
||||
Preview\XBitmap::class,
|
||||
Preview\Krita::class,
|
||||
];
|
||||
|
||||
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
|
||||
Preview\MarkDown::class,
|
||||
Preview\MP3::class,
|
||||
Preview\TXT::class,
|
||||
Preview\OpenDocument::class,
|
||||
], $imageProviders));
|
||||
|
||||
if (in_array(Preview\Image::class, $this->defaultProviders)) {
|
||||
|
@ -339,7 +341,9 @@ class PreviewManager implements IPreview {
|
|||
$this->registerCoreProvider(Preview\GIF::class, '/image\/gif/');
|
||||
$this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/');
|
||||
$this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/');
|
||||
$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
|
||||
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
|
||||
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
|
||||
|
||||
// SVG, Office and Bitmap require imagick
|
||||
if (extension_loaded('imagick')) {
|
||||
|
|
Loading…
Reference in New Issue