Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
317521b
feat(SpeechToText): Add SpeechToText provider API
marcelklehr Apr 11, 2023
f2eb224
feat(SpeechToText): Add autoload changes
marcelklehr Apr 11, 2023
a9b5d1f
chore(coding style): Run cs:fix
marcelklehr Apr 11, 2023
1833d93
chore(coding style): Run cs:fix
marcelklehr Apr 11, 2023
ef7ce88
ISpeechToTextProvider#transcribeFile: Pass \OCP\Files\File instead of…
marcelklehr Apr 12, 2023
176f1af
ISpeechToTextManager: Take File as input, drop $context
marcelklehr Apr 13, 2023
a8d3fff
Split TranscriptionFinishedEvent into Successful and Failed events
marcelklehr Apr 13, 2023
865ebfa
Add missing strict_types + author + copyright
marcelklehr Apr 13, 2023
ad66180
Update lib/private/SpeechToText/SpeechToTextManager.php
marcelklehr Apr 13, 2023
71523b9
AbstractTranscriptionEvent: Add File param
marcelklehr Apr 17, 2023
ad1a0d8
Transcription*Event: Add doc block
marcelklehr Apr 17, 2023
3779cc3
SpeechToTextManager: Deduplicate transcription jobs
marcelklehr Apr 17, 2023
6e9f260
Update lib/private/SpeechToText/SpeechToTextManager.php
marcelklehr Apr 17, 2023
aac6a18
Update lib/public/SpeechToText/ISpeechToTextManager.php
marcelklehr Apr 17, 2023
b082657
Update lib/public/SpeechToText/ISpeechToTextManager.php
marcelklehr Apr 17, 2023
47cff5d
Update lib/public/SpeechToText/ISpeechToTextManager.php
marcelklehr Apr 17, 2023
3f57725
SpeechToTextManager#transcribeFile: Try next provider if one fails
marcelklehr Apr 17, 2023
bef4cf0
Fix missing import
nickvergessen Apr 18, 2023
9649f91
Update lib/private/SpeechToText/SpeechToTextManager.php
marcelklehr Apr 18, 2023
ce651e5
Run cs:fix
marcelklehr Apr 18, 2023
eb996cb
TranscriptionJob: Ensure filesystem is setup before trying to retriev…
marcelklehr Apr 18, 2023
a8b27c9
TranscriptionJob: Add owner argument to simplify filesystem setup
marcelklehr Apr 19, 2023
a2f5421
SpeechToTextManager#scheduleFileTranscription: Take context params an…
marcelklehr Apr 19, 2023
fbcd275
Context params: Make userId nullable
marcelklehr Apr 19, 2023
db9901a
Fix(docs): Fix parameter type in doc block
nickvergessen Apr 19, 2023
ab7b63d
fix(autoloader): Rebuild
nickvergessen Apr 19, 2023
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
Prev Previous commit
Next Next commit
TranscriptionJob: Ensure filesystem is setup before trying to retriev…
…e file

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Apr 18, 2023
commit eb996cbbb0149b82f7fefc5430b2f3629d7930ba
56 changes: 54 additions & 2 deletions lib/private/SpeechToText/TranscriptionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
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;
Expand All @@ -44,6 +49,7 @@ public function __construct(
private IEventDispatcher $eventDispatcher,
private IRootFolder $rootFolder,
private LoggerInterface $logger,
private IUserMountCache $userMountCache,
) {
parent::__construct($timeFactory);
}
Expand All @@ -56,7 +62,7 @@ protected function run($argument) {
$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(
Expand All @@ -76,7 +82,7 @@ protected function run($argument) {
$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(
Expand All @@ -87,4 +93,50 @@ protected function run($argument) {
);
}
}

/**
* @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);
}
}