Skip to content

Commit

Permalink
Merge pull request #71 from nextcloud/fix/tmp-file-doc-conversion
Browse files Browse the repository at this point in the history
fix: use ITempManager instead of manually handling temp files
  • Loading branch information
julien-nc authored Apr 16, 2024
2 parents 39f59bb + bf7b791 commit f7cfa2d
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IL10N;
use OCP\ITempManager;
use OCP\Lock\LockedException;
use OCP\PreConditionNotMetException;
use OCP\SpeechToText\ISpeechToTextManager;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function __construct(
private IJobList $jobList,
private IL10N $l10n,
private ContainerInterface $container,
private ITempManager $tempManager,
) {
}

Expand Down Expand Up @@ -437,19 +439,10 @@ public function parseTextFromFile(string $filePath, string $userId): string {
case 'application/msword':
case 'application/vnd.oasis.opendocument.text':
{
// Store the file in a temp dir and provide a path for the doc parser to use
$tempFilePath = sys_get_temp_dir() . '/assistant_app/' . uniqid() . '.tmp';
// Make sure the temp dir exists
if (!file_exists(dirname($tempFilePath))) {
mkdir(dirname($tempFilePath), 0700, true);
}
$tempFilePath = $this->tempManager->getTemporaryFile();
file_put_contents($tempFilePath, $fileContent);

$text = $this->parseDocument($tempFilePath, $mimeType);

// Remove the hardlink to the file (delete it):
unlink($tempFilePath);

$this->tempManager->clean();
break;
}
}
Expand Down

0 comments on commit f7cfa2d

Please sign in to comment.