diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-04-18 16:23:45 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-04-18 16:24:06 +0200 |
commit | eb996cbbb0149b82f7fefc5430b2f3629d7930ba (patch) | |
tree | 1ad2b425dccc223f32bbff4163b4cefe53d6acf2 /lib | |
parent | ce651e53b9f5e8942b73505eba2f0f3b55dade6d (diff) | |
download | nextcloud-server-eb996cbbb0149b82f7fefc5430b2f3629d7930ba.tar.gz nextcloud-server-eb996cbbb0149b82f7fefc5430b2f3629d7930ba.zip |
TranscriptionJob: Ensure filesystem is setup before trying to retrieve file
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/SpeechToText/TranscriptionJob.php | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php index fd175e774a5..223697d4bb5 100644 --- a/lib/private/SpeechToText/TranscriptionJob.php +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -29,8 +29,13 @@ namespace OC\SpeechToText; 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; use OCP\SpeechToText\Events\TranscriptionFailedEvent; use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent; @@ -44,6 +49,7 @@ class TranscriptionJob extends QueuedJob { private IEventDispatcher $eventDispatcher, private IRootFolder $rootFolder, private LoggerInterface $logger, + private IUserMountCache $userMountCache, ) { parent::__construct($timeFactory); } @@ -56,7 +62,7 @@ class TranscriptionJob extends QueuedJob { $fileId = $argument['fileId']; $file = null; try { - $file = current($this->rootFolder->getById($fileId)); + $file = $this->getFileFromId($fileId); if (!($file instanceof File)) { $this->logger->warning('Transcription of file ' . $fileId . ' failed. The file could not be found'); $this->eventDispatcher->dispatchTyped( @@ -76,7 +82,7 @@ class TranscriptionJob extends QueuedJob { $result, ) ); - } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException $e) { + } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException $e) { $this->logger->warning('Transcription of file ' . $fileId . ' failed', ['exception' => $e]); $this->eventDispatcher->dispatchTyped( new TranscriptionFailedEvent( @@ -87,4 +93,50 @@ 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); + } } |