Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use ITempManager instead of manually handling temp files #71

Merged
merged 1 commit into from
Apr 16, 2024
Merged
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
15 changes: 4 additions & 11 deletions lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,7 @@ public function __construct(
private IJobList $jobList,
private IL10N $l10n,
private ContainerInterface $container,
private ITempManager $tempManager,
) {
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
Loading