From bf7b7917647812c6d677def89c17cf626bb325c8 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Tue, 16 Apr 2024 13:54:18 +0530 Subject: [PATCH] fix: use ITempManager instead of manually handling temp files Signed-off-by: Anupam Kumar --- lib/Service/AssistantService.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/Service/AssistantService.php b/lib/Service/AssistantService.php index f4572d40..5d073113 100644 --- a/lib/Service/AssistantService.php +++ b/lib/Service/AssistantService.php @@ -21,6 +21,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; @@ -54,6 +55,7 @@ public function __construct( private IJobList $jobList, private IL10N $l10n, private ContainerInterface $container, + private ITempManager $tempManager, ) { } @@ -439,19 +441,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; } }