Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/documentserver_community.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-01-29 17:43:15 +0300
committerRobin Appelman <robin@icewind.nl>2020-01-29 17:43:15 +0300
commit330536c7618c653a93817c5a6ef15455dad2fff2 (patch)
tree40e5ef4b953c9011334ea17c5b4bc12abd411220
parent3d18bc2967ba3125651c2950ccdaa11512cee6fd (diff)
implement 'Convert with ONLYOFFICE'
-rw-r--r--lib/Controller/ConvertController.php36
-rw-r--r--lib/Document/DocumentStore.php13
2 files changed, 46 insertions, 3 deletions
diff --git a/lib/Controller/ConvertController.php b/lib/Controller/ConvertController.php
index 51d6e98..fec5257 100644
--- a/lib/Controller/ConvertController.php
+++ b/lib/Controller/ConvertController.php
@@ -21,11 +21,25 @@
namespace OCA\DocumentServer\Controller;
+use OCA\DocumentServer\Document\DocumentStore;
+use OCA\DocumentServer\OnlyOffice\URLDecoder;
use OCA\DocumentServer\XMLResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
+use OCP\IURLGenerator;
class ConvertController extends Controller {
+ private $documentStore;
+ private $urlDecoder;
+ private $urlGenerator;
+
+ public function __construct(DocumentStore $documentStore, URLDecoder $urlDecoder, IURLGenerator $urlGenerator) {
+ $this->documentStore = $documentStore;
+ $this->urlDecoder = $urlDecoder;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+
/**
* @NoAdminRequired
* @NoCSRFRequired
@@ -36,10 +50,26 @@ class ConvertController extends Controller {
return new XMLResponse([
'FileUrl' => $url,
'Percent' => "100",
- 'EndConvert' => "True"
+ 'EndConvert' => "True",
]);
- }
+ } else {
+ $documentId = (int)$key;
+ $documentFile = $this->urlDecoder->getFileForUrl($url);
+ $this->documentStore->getDocumentForEditor($documentId, $documentFile, $filetype);
+ $this->documentStore->convert($documentId, $outputtype);
+
+ $url = $this->urlGenerator->linkToRouteAbsolute(
+ 'documentserver_community.Document.documentFile', [
+ 'path' => '/convert.' . $outputtype,
+ 'docId' => $documentId,
+ ]
+ );
- return false;
+ return new XMLResponse([
+ 'FileUrl' => $url,
+ 'Percent' => "100",
+ 'EndConvert' => "True",
+ ]);
+ }
}
}
diff --git a/lib/Document/DocumentStore.php b/lib/Document/DocumentStore.php
index 172f8a3..2eefbc4 100644
--- a/lib/Document/DocumentStore.php
+++ b/lib/Document/DocumentStore.php
@@ -233,4 +233,17 @@ class DocumentStore {
return $title;
}
+
+ public function convert(int $documentId, string $targetFormat): string {
+ $docFolder = $this->getDocumentFolder($documentId);
+
+ $this->localAppData->getReadWriteLocalPath($docFolder, function (string $localPath) use ($targetFormat) {
+ $command = new ConvertCommand($localPath . '/Editor.bin', $localPath . '/convert.' . $targetFormat);
+ $command->setTargetFormat(DocumentFormat::getFormatFromExtension($targetFormat));
+
+ $this->documentConverter->runCommand($command);
+ });
+
+ return '/convert.' . $targetFormat;
+ }
}