Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions lib/Service/DocumentGenerationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function generateTextDocument(?string $userId, string $description, strin
$converter = new GithubFlavoredMarkdownConverter();
$htmlContent = $converter->convert($markdownContent)->getContent();
$htmlStream = $this->stringToStream($htmlContent);
$docxContent = $this->remoteService->convertTo('document.html', $htmlStream, $targetFormat, true);
$docxContent = $this->remoteService->convertTo('document.html', $htmlStream, $targetFormat);

return $docxContent;
}
Expand All @@ -58,7 +58,19 @@ public function generateSpreadSheetDocument(?string $userId, string $description
$taskInput = $prompt . "\n\n" . $description;
$csvContent = $this->runTextToTextTask($taskInput, $userId);
$csvStream = $this->stringToStream($csvContent);
$xlsxContent = $this->remoteService->convertTo('document.csv', $csvStream, $targetFormat, true);

// Passing these will ensure the CSV is correctly
// parsed into a spreadsheet
$conversionOptions = [
// Sets the input filter to use the following:
// 44 - , (comma) as the field separator
// 34 - " (double quote) as the text delimiter
// 76 - UTF-8 as the character set
// 1 - Start at line one of the input
'infilterOptions' => '44,34,76,1',
];

$xlsxContent = $this->remoteService->convertTo('document.csv', $csvStream, $targetFormat, $conversionOptions);

return $xlsxContent;
}
Expand Down
14 changes: 8 additions & 6 deletions lib/Service/RemoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function convertFileTo(File $file, string $format) {
* @param resource $stream
* @return resource|string
*/
public function convertTo(string $filename, $stream, string $format, bool $sendFilename = false) {
public function convertTo(string $filename, $stream, string $format, ?array $conversionOptions = []) {
$client = $this->clientService->newClient();
$options = RemoteOptionsService::getDefaultOptions();
// FIXME: can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream
Expand All @@ -82,11 +82,13 @@ public function convertTo(string $filename, $stream, string $format, bool $sendF
$options['verify'] = false;
}

$options['multipart'] = [['name' => $filename, 'contents' => $stream]];
// collabora does not want to read the input if there is no filename (for csv content for example)
if ($sendFilename) {
$options['multipart'][0]['filename'] = $filename;
}
$options['multipart'] = [
array_merge([
'name' => $filename,
'filename' => $filename,
'contents' => $stream
], $conversionOptions),
];

try {
$response = $client->post($this->appConfig->getCollaboraUrlInternal() . '/cool/convert-to/' . $format, $options);
Expand Down
Loading