diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-04-13 12:12:07 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-04-13 12:12:07 +0200 |
commit | a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8 (patch) | |
tree | 6115b6748d00997155016d708879e796bfe21344 /lib/private/SpeechToText/TranscriptionJob.php | |
parent | 176f1af26a6bf7c62cadd04448b73839296653c0 (diff) | |
download | nextcloud-server-a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8.tar.gz nextcloud-server-a8d3fff648c4c6f5be3e37c09f9168e5b7c0e8f8.zip |
Split TranscriptionFinishedEvent into Successful and Failed events
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/SpeechToText/TranscriptionJob.php')
-rw-r--r-- | lib/private/SpeechToText/TranscriptionJob.php | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php index 296a713593b..775a2a7fadc 100644 --- a/lib/private/SpeechToText/TranscriptionJob.php +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -5,9 +5,11 @@ namespace OC\SpeechToText; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\QueuedJob; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\PreConditionNotMetException; -use OCP\SpeechToText\Events\TranscriptionFinishedEvent; +use OCP\SpeechToText\Events\TranscriptionFailedEvent; +use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent; use OCP\SpeechToText\ISpeechToTextManager; class TranscriptionJob extends QueuedJob { @@ -25,24 +27,30 @@ class TranscriptionJob extends QueuedJob { * @inheritDoc */ protected function run($argument) { + $fileId = $argument['fileId']; try { - $file = $this->rootFolder->getById($argument['fileId']); + $file = current($this->rootFolder->getById($fileId)); + if (!($file instanceof File)) { + $this->eventDispatcher->dispatchTyped( + new TranscriptionFailedEvent( + $fileId, + 'File not found', + ) + ); + return; + } $result = $this->speechToTextManager->transcribeFile($file); $this->eventDispatcher->dispatchTyped( - new TranscriptionFinishedEvent( - true, + new TranscriptionSuccessfulEvent( + $fileId, $result, - '', - $argument['context'] ) ); } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException $e) { $this->eventDispatcher->dispatchTyped( - new TranscriptionFinishedEvent( - false, - '', + new TranscriptionFailedEvent( + $fileId, $e->getMessage(), - $argument['context'] ) ); } |