diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-04-19 11:26:04 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-04-19 11:26:04 +0200 |
commit | a8b27c91265a883aaa1563c33edf8d6917af63b1 (patch) | |
tree | 09047212770b6dc2993649f178927c822a6b4fd2 /lib | |
parent | eb996cbbb0149b82f7fefc5430b2f3629d7930ba (diff) | |
download | nextcloud-server-a8b27c91265a883aaa1563c33edf8d6917af63b1.tar.gz nextcloud-server-a8b27c91265a883aaa1563c33edf8d6917af63b1.zip |
TranscriptionJob: Add owner argument to simplify filesystem setup
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/SpeechToText/SpeechToTextManager.php | 2 | ||||
-rw-r--r-- | lib/private/SpeechToText/TranscriptionJob.php | 58 |
2 files changed, 7 insertions, 53 deletions
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php index 9ab53a8013d..d6f7e74c95e 100644 --- a/lib/private/SpeechToText/SpeechToTextManager.php +++ b/lib/private/SpeechToText/SpeechToTextManager.php @@ -95,7 +95,7 @@ class SpeechToTextManager implements ISpeechToTextManager { throw new PreConditionNotMetException('No SpeechToText providers have been registered'); } try { - $this->jobList->add(TranscriptionJob::class, ['fileId' => $file->getId()]); + $this->jobList->add(TranscriptionJob::class, ['fileId' => $file->getId(), 'owner' => $file->getOwner()->getUID()]); } catch (NotFoundException|InvalidPathException $e) { throw new InvalidArgumentException('Invalid file provided for file transcription: ' . $e->getMessage()); } diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php index 223697d4bb5..c77ae23ac02 100644 --- a/lib/private/SpeechToText/TranscriptionJob.php +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -26,14 +26,12 @@ declare(strict_types=1); namespace OC\SpeechToText; +use OC\User\NoUserException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\QueuedJob; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Config\ICachedMountFileInfo; -use OCP\Files\Config\IUserMountCache; use OCP\Files\File; use OCP\Files\IRootFolder; -use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\PreConditionNotMetException; @@ -49,7 +47,6 @@ class TranscriptionJob extends QueuedJob { private IEventDispatcher $eventDispatcher, private IRootFolder $rootFolder, private LoggerInterface $logger, - private IUserMountCache $userMountCache, ) { parent::__construct($timeFactory); } @@ -60,9 +57,12 @@ class TranscriptionJob extends QueuedJob { */ protected function run($argument) { $fileId = $argument['fileId']; + $owner = $argument['owner']; $file = null; try { - $file = $this->getFileFromId($fileId); + \OC_Util::setupFS($owner); + $userFolder = $this->rootFolder->getUserFolder($owner); + $file = current($userFolder->getById($fileId)); if (!($file instanceof File)) { $this->logger->warning('Transcription of file ' . $fileId . ' failed. The file could not be found'); $this->eventDispatcher->dispatchTyped( @@ -82,7 +82,7 @@ class TranscriptionJob extends QueuedJob { $result, ) ); - } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException $e) { + } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|NoUserException $e) { $this->logger->warning('Transcription of file ' . $fileId . ' failed', ['exception' => $e]); $this->eventDispatcher->dispatchTyped( new TranscriptionFailedEvent( @@ -93,50 +93,4 @@ class TranscriptionJob extends QueuedJob { ); } } - - /** - * @throws NotFoundException - */ - private function getFileFromId(int $fileId): Node { - $mountPoints = $this->userMountCache->getMountsForFileId($fileId); - if (empty($mountPoints)) { - throw new NotFoundException("No mount points found for file $fileId"); - } - - foreach ($mountPoints as $mountPoint) { - try { - return $this->getCreatableNodeFromMountPoint($mountPoint, $fileId); - } catch (NotPermittedException $e) { - // Check the next mount point - $this->logger->debug('Mount point ' . ($mountPoint->getMountId() ?? 'null') . ' has no delete permissions for file ' . $fileId); - } catch (NotFoundException $e) { - // Already logged explicitly inside - } - } - - throw new NotFoundException("No mount point with delete permissions found for file $fileId"); - } - - /** - * @throws NotFoundException - */ - protected function getCreatableNodeFromMountPoint(ICachedMountFileInfo $mountPoint, int $fileId): Node { - try { - $userId = $mountPoint->getUser()->getUID(); - $userFolder = $this->rootFolder->getUserFolder($userId); - \OC_Util::setupFS($userId); - } catch (\Exception $e) { - $this->logger->debug($e->getMessage(), [ - 'exception' => $e, - ]); - throw new NotFoundException('Could not get user', 0, $e); - } - - $nodes = $userFolder->getById($fileId); - if (empty($nodes)) { - throw new NotFoundException('No node for file ' . $fileId . ' and user ' . $userId); - } - - return array_shift($nodes); - } } |