解决Nextcloud Preview Generate 禁用word excel pdf失效

2024-08-29 320 0

vim config/config.php
...
  'enable_previews' => true,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\HEIC',
    4 => 'OC\\Preview\\BMP',
  ),
  'preview_max_x' => 1024,
  'preview_max_y' => 1024,

enabledPreviewProviders 配置了指定类型
但在执行提前生成预览过程,依旧发现在生成doc、excel、pdf,而且生成非常费时。

php /var/www/html/occ preview:generate-all -vvv

无效原因:是因为安装了onlyoffice插件,自动注册文档预览

cat apps/onlyoffice/lib/Preview.php
...
use OC\Preview\Provider;
...
    /**
     * Capabilities mimetype
     *
     * @var Array
     */
    public static $capabilities = [
        "text/csv",
        "application/msword",
        "application/vnd.ms-word.document.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
        "application/epub+zip",
        "text/html",
        "application/vnd.oasis.opendocument.presentation",
        "application/vnd.oasis.opendocument.spreadsheet",
        "application/vnd.oasis.opendocument.text",
        "application/vnd.oasis.opendocument.presentation-template",
        "application/vnd.oasis.opendocument.spreadsheet-template",
        "application/vnd.oasis.opendocument.text-template",
        "application/pdf",
        "application/vnd.ms-powerpoint.template.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.presentationml.template",
        "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
        "application/vnd.ms-powerpoint",
        "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.presentationml.presentation",
        "text/rtf",
        "text/plain",
        "application/vnd.ms-excel",
        "application/vnd.ms-excel.sheet.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "application/vnd.ms-excel.template.macroEnabled.12",
        "application/vnd.openxmlformats-officedocument.spreadsheetml.template"
    ];

    /**
     * Return mime type
     */
    public static function getMimeTypeRegex() {
        $mimeTypeRegex = "";
        foreach (self::$capabilities as $format) {
            if (!empty($mimeTypeRegex)) {
                $mimeTypeRegex = $mimeTypeRegex . "|";
            }
            $mimeTypeRegex = $mimeTypeRegex . str_replace("/", "\/", $format);
        }
        $mimeTypeRegex = "/" . $mimeTypeRegex . "/";

        return $mimeTypeRegex;
    }

解决
onlyoffice 禁用preview注册

vim apps/onlyoffice/lib/AppInfo/Application.php

        // preview disable sunday 20240829
        /*
        $previewManager = $container->query(IPreview::class);
        $previewManager->registerProvider(Preview::getMimeTypeRegex(), function () use ($container) {
            return $container->query(Preview::class);
        });
         */

https://github.com/nextcloud/previewgenerator/issues/410

相关文章

nextcloud preview-generate 报错文件无权限解决
Ubuntu 16.04 编译PHP7.1时出现:collect2: error: ld returned 1 exit status make: *** [sapi/cli/php] Error 1

发布评论