Add preview provider for ODF that uses Collabora Online's web API

This commit is contained in:
Tor Lillqvist 2018-07-19 13:57:55 +03:00 коммит произвёл Roeland Jago Douma
Родитель 34923a97e7
Коммит 7abe2f88f0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F941078878347C0C
8 изменённых файлов: 232 добавлений и 1 удалений

Просмотреть файл

@ -66,3 +66,6 @@ if ($wopiUrl !== '') {
$policy->addAllowedFrameDomain($wopiUrl);
$manager->addDefaultPolicy($policy);
}
$app = new Application();
$app->registerProvider();

Просмотреть файл

@ -9,6 +9,8 @@
<author>Collabora Productivity based on work of Frank Karlitschek, Victor Dubiniuk</author>
<types>
<prevent_group_restriction/>
<filesystem/>
<dav/>
</types>
<documentation>
<user>https://nextcloud.com/collaboraonline/</user>

Просмотреть файл

@ -23,9 +23,13 @@ namespace OCA\Richdocuments\AppInfo;
use OC\AppFramework\Utility\TimeFactory;
use OCA\Richdocuments\Capabilities;
use OCA\Richdocuments\WOPI\DiscoveryManager;
use OCA\Richdocuments\Preview\MSExcel;
use OCA\Richdocuments\Preview\MSWord;
use OCA\Richdocuments\Preview\OOXML;
use OCA\Richdocuments\Preview\OpenDocument;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\IPreview;
class Application extends App {
@ -36,4 +40,30 @@ class Application extends App {
$this->getContainer()->registerCapability(Capabilities::class);
}
public function registerProvider() {
$container = $this->getContainer();
/** @var IPreview $previewManager */
$previewManager = $container->query(IPreview::class);
$previewManager->registerProvider('/application\/vnd.ms-excel/', function() use ($container) {
return $container->query(MSExcel::class);
});
$previewManager->registerProvider('/application\/msword/', function() use ($container) {
return $container->query(MSWord::class);
});
$previewManager->registerProvider('/application\/vnd.openxmlformats-officedocument.*/', function() use ($container) {
return $container->query(OOXML::class);
});
// \OC::$server->getLogger()->debug('==== Richdocuments Application registerProvider: calling manager registerProvider:');
$previewManager->registerProvider('/application\/vnd.oasis.opendocument.*/', function() use ($container) {
// \OC::$server->getLogger()->debug('==== Richdocuments Application registerProvider lambda. OpenDocument::class=' . OpenDocument::class);
return $container->query(OpenDocument::class);
});
}
}

31
lib/Preview/MSExcel.php Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2018, Collabora Productivity.
*
* @author Tor Lillqvist <tml@collabora.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Richdocuments\Preview;
class MSExcel extends Office {
/**
* {@inheritDoc}
*/
public function getMimeType() {
return '/application\/vnd.ms-excel/';
}
}

31
lib/Preview/MSWord.php Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2018, Collabora Productivity.
*
* @author Tor Lillqvist <tml@collabora.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Richdocuments\Preview;
class MSWord extends Office {
/**
* {@inheritDoc}
*/
public function getMimeType() {
return '/application\/msword/';
}
}

31
lib/Preview/OOXML.php Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2018, Collabora Productivity.
*
* @author Tor Lillqvist <tml@collabora.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Richdocuments\Preview;
class OOXML extends Office {
/**
* {@inheritDoc}
*/
public function getMimeType() {
return '/application\/vnd.openxmlformats-officedocument.*/';
}
}

71
lib/Preview/Office.php Normal file
Просмотреть файл

@ -0,0 +1,71 @@
<?php
/**
* @copyright Copyright (c) 2018, Collabora Productivity.
*
* @author Tor Lillqvist <tml@collabora.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Richdocuments\Preview;
use OC\Preview\Provider;
use \GuzzleHttp\Client;
use \GuzzleHttp\Post\PostFile;
abstract class Office extends Provider {
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
// \OC::$server->getLogger()->debug('==== getThumbnail: ' . $path);
$data = $fileview->file_get_contents($path);
$client = new Client(['base_uri' => 'http://localhost:9980/', 'timeout' => 2.0]);
$request = $client->createRequest('POST', 'http://localhost:9980/lool/convert-to/png',
[
'body' =>
[
new PostFile($path, $data)
]
]);
$response = $client->send($request);
/*
$headers = $response->getHeaders();
foreach ($headers as $key => $value) {
$concatvalue = '';
foreach ($value as $vvalue) {
$concatvalue = $concatvalue . $vvalue;
}
// \OC::$server->getLogger()->debug('==== response: ' . $key . ': ' . $concatvalue);
}
\OC::$server->getLogger()->debug('==== response body type: ' . gettype($response->getBody()));
*/
$image = new \OC_Image();
$image->loadFromData($response->getBody());
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
}

Просмотреть файл

@ -0,0 +1,32 @@
<?php
/**
* @copyright Copyright (c) 2018, Collabora Productivity.
*
* @author Tor Lillqvist <tml@collabora.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Richdocuments\Preview;
//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
class OpenDocument extends Office {
/**
* {@inheritDoc}
*/
public function getMimeType() {
return '/application\/vnd.oasis.opendocument.*/';
}
}