Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 30 additions & 44 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,34 @@
use function array_key_exists;

class PreviewManager implements IPreview {
protected IConfig $config;
protected IRootFolder $rootFolder;
protected IAppData $appData;
protected IEventDispatcher $eventDispatcher;
private ?Generator $generator = null;
private GeneratorHelper $helper;
protected bool $providerListDirty = false;
protected bool $registeredCoreProviders = false;
protected array $providers = [];

/** @var array mime type => support status */
protected array $mimeTypeSupportMap = [];
protected ?array $defaultProviders = null;
protected ?string $userId;
private Coordinator $bootstrapCoordinator;

/**
* Hash map (without value) of loaded bootstrap providers
* @psalm-var array<string, null>
*/
private array $loadedBootstrapProviders = [];
private ContainerInterface $container;
private IBinaryFinder $binaryFinder;
private IMagickSupport $imagickSupport;
private bool $enablePreviews;

public function __construct(
IConfig $config,
IRootFolder $rootFolder,
IAppData $appData,
IEventDispatcher $eventDispatcher,
GeneratorHelper $helper,
?string $userId,
Coordinator $bootstrapCoordinator,
ContainerInterface $container,
IBinaryFinder $binaryFinder,
IMagickSupport $imagickSupport,
protected IConfig $config,
protected IRootFolder $rootFolder,
protected IAppData $appData,
protected IEventDispatcher $eventDispatcher,
private GeneratorHelper $helper,
protected ?string $userId,
private Coordinator $bootstrapCoordinator,
private ContainerInterface $container,
private IBinaryFinder $binaryFinder,
private IMagickSupport $imagickSupport,
) {
$this->config = $config;
$this->rootFolder = $rootFolder;
$this->appData = $appData;
$this->eventDispatcher = $eventDispatcher;
$this->helper = $helper;
$this->userId = $userId;
$this->bootstrapCoordinator = $bootstrapCoordinator;
$this->container = $container;
$this->binaryFinder = $binaryFinder;
$this->imagickSupport = $imagickSupport;
$this->enablePreviews = $config->getSystemValueBool('enable_previews', true);
}

Expand Down Expand Up @@ -226,7 +206,7 @@ public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null)
}

$mount = $file->getMountPoint();
if ($mount and !$mount->getOption('previews', true)) {
if ($mount && !$mount->getOption('previews', true)) {
return false;
}

Expand Down Expand Up @@ -330,19 +310,25 @@ protected function registerCoreProviders() {
}
$this->registeredCoreProviders = true;

$this->registerCoreProvider(Preview\TXT::class, '/text\/plain/');
$this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/');
$this->registerCoreProvider(Preview\PNG::class, '/image\/png/');
$this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/');
$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\WebP::class, '/image\/webp/');
$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg$/');
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
$this->registerCoreProvider(Preview\ImaginaryPDF::class, Preview\ImaginaryPDF::supportedMimeTypes());
$mimeTypeConfig = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how's that better than before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this just adds unnecessary lines of code 🤷‍♀️

Preview\TXT::class => '/text\/plain/',
Preview\MarkDown::class => '/text\/(x-)?markdown/',
Preview\PNG::class => '/image\/png/',
Preview\JPEG::class => '/image\/jpeg/',
Preview\GIF::class => '/image\/gif/',
Preview\BMP::class => '/image\/bmp/',
Preview\XBitmap::class => '/image\/x-xbitmap/',
Preview\WebP::class => '/image\/webp/',
Preview\Krita::class => '/application\/x-krita/',
Preview\MP3::class => '/audio\/mpeg/',
Preview\OpenDocument::class => '/application\/vnd\.oasis\.opendocument\.[a-z]+/',
Preview\Imaginary::class => Preview\Imaginary::supportedMimeTypes(),
Preview\ImaginaryPDF::class => Preview\ImaginaryPDF::supportedMimeTypes(),
];

foreach ($mimeTypeConfig as $class => $mimeType) {
$this->registerCoreProvider($class, $mimeType);
}

// SVG and Bitmap require imagick
if ($this->imagickSupport->hasExtension()) {
Expand Down
Loading