Skip to content

Commit b490cd3

Browse files
authored
Merge pull request #4843 from nextcloud/feat/ai-csv-conversion
2 parents 7b667c3 + ef88502 commit b490cd3

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

lib/Service/DocumentGenerationService.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function generateTextDocument(?string $userId, string $description, strin
4848
$converter = new GithubFlavoredMarkdownConverter();
4949
$htmlContent = $converter->convert($markdownContent)->getContent();
5050
$htmlStream = $this->stringToStream($htmlContent);
51-
$docxContent = $this->remoteService->convertTo('document.html', $htmlStream, $targetFormat, true);
51+
$docxContent = $this->remoteService->convertTo('document.html', $htmlStream, $targetFormat);
5252

5353
return $docxContent;
5454
}
@@ -58,7 +58,19 @@ public function generateSpreadSheetDocument(?string $userId, string $description
5858
$taskInput = $prompt . "\n\n" . $description;
5959
$csvContent = $this->runTextToTextTask($taskInput, $userId);
6060
$csvStream = $this->stringToStream($csvContent);
61-
$xlsxContent = $this->remoteService->convertTo('document.csv', $csvStream, $targetFormat, true);
61+
62+
// Passing these will ensure the CSV is correctly
63+
// parsed into a spreadsheet
64+
$conversionOptions = [
65+
// Sets the input filter to use the following:
66+
// 44 - , (comma) as the field separator
67+
// 34 - " (double quote) as the text delimiter
68+
// 76 - UTF-8 as the character set
69+
// 1 - Start at line one of the input
70+
'infilterOptions' => '44,34,76,1',
71+
];
72+
73+
$xlsxContent = $this->remoteService->convertTo('document.csv', $csvStream, $targetFormat, $conversionOptions);
6274

6375
return $xlsxContent;
6476
}

lib/Service/RemoteService.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function convertFileTo(File $file, string $format) {
7272
* @param resource $stream
7373
* @return resource|string
7474
*/
75-
public function convertTo(string $filename, $stream, string $format, bool $sendFilename = false) {
75+
public function convertTo(string $filename, $stream, string $format, ?array $conversionOptions = []) {
7676
$client = $this->clientService->newClient();
7777
$options = RemoteOptionsService::getDefaultOptions();
7878
// FIXME: can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream
@@ -82,11 +82,13 @@ public function convertTo(string $filename, $stream, string $format, bool $sendF
8282
$options['verify'] = false;
8383
}
8484

85-
$options['multipart'] = [['name' => $filename, 'contents' => $stream]];
86-
// collabora does not want to read the input if there is no filename (for csv content for example)
87-
if ($sendFilename) {
88-
$options['multipart'][0]['filename'] = $filename;
89-
}
85+
$options['multipart'] = [
86+
array_merge([
87+
'name' => $filename,
88+
'filename' => $filename,
89+
'contents' => $stream
90+
], $conversionOptions),
91+
];
9092

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

0 commit comments

Comments
 (0)