aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-04-19 12:35:13 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-04-19 12:35:13 +0200
commita2f5421fc3eb13ed28167e97483fa7eaa4e65841 (patch)
treeeec8142c6eb4c88afb3309361a23c64a2d07a554 /lib
parenta8b27c91265a883aaa1563c33edf8d6917af63b1 (diff)
downloadnextcloud-server-a2f5421fc3eb13ed28167e97483fa7eaa4e65841.tar.gz
nextcloud-server-a2f5421fc3eb13ed28167e97483fa7eaa4e65841.zip
SpeechToTextManager#scheduleFileTranscription: Take context params and expose them on the Transcription*Events
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/SpeechToText/SpeechToTextManager.php9
-rw-r--r--lib/private/SpeechToText/TranscriptionJob.php8
-rw-r--r--lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php16
-rw-r--r--lib/public/SpeechToText/Events/TranscriptionFailedEvent.php6
-rw-r--r--lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php6
-rw-r--r--lib/public/SpeechToText/ISpeechToTextManager.php5
6 files changed, 43 insertions, 7 deletions
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php
index d6f7e74c95e..95208e5b0ca 100644
--- a/lib/private/SpeechToText/SpeechToTextManager.php
+++ b/lib/private/SpeechToText/SpeechToTextManager.php
@@ -90,12 +90,17 @@ class SpeechToTextManager implements ISpeechToTextManager {
return !empty($context->getSpeechToTextProviders());
}
- public function scheduleFileTranscription(File $file): void {
+ public function scheduleFileTranscription(File $file, string $userId, string $appId): void {
if (!$this->hasProviders()) {
throw new PreConditionNotMetException('No SpeechToText providers have been registered');
}
try {
- $this->jobList->add(TranscriptionJob::class, ['fileId' => $file->getId(), 'owner' => $file->getOwner()->getUID()]);
+ $this->jobList->add(TranscriptionJob::class, [
+ 'fileId' => $file->getId(),
+ 'owner' => $file->getOwner()->getUID(),
+ 'userId' => $userId,
+ 'appId' => $appId,
+ ]);
} 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 c77ae23ac02..d5cc9ed7c38 100644
--- a/lib/private/SpeechToText/TranscriptionJob.php
+++ b/lib/private/SpeechToText/TranscriptionJob.php
@@ -58,6 +58,8 @@ class TranscriptionJob extends QueuedJob {
protected function run($argument) {
$fileId = $argument['fileId'];
$owner = $argument['owner'];
+ $userId = $argument['userId'];
+ $appId = $argument['appId'];
$file = null;
try {
\OC_Util::setupFS($owner);
@@ -70,6 +72,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
null,
'File not found',
+ $userId,
+ $appId,
)
);
return;
@@ -80,6 +84,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
$file,
$result,
+ $userId,
+ $appId,
)
);
} catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|NoUserException $e) {
@@ -89,6 +95,8 @@ class TranscriptionJob extends QueuedJob {
$fileId,
$file,
$e->getMessage(),
+ $userId,
+ $appId,
)
);
}
diff --git a/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php
index 0f906a7604b..74164791b32 100644
--- a/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php
+++ b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php
@@ -38,6 +38,8 @@ abstract class AbstractTranscriptionEvent extends Event {
public function __construct(
private int $fileIdId,
private ?File $file,
+ private string $userId,
+ private string $appId,
) {
parent::__construct();
}
@@ -55,4 +57,18 @@ abstract class AbstractTranscriptionEvent extends Event {
public function getFile(): ?File {
return $this->file;
}
+
+ /**
+ * @since 27.0.0
+ */
+ public function getUserId(): string {
+ return $this->userId;
+ }
+
+ /**
+ * @since 27.0.0
+ */
+ public function getAppId(): string {
+ return $this->appId;
+ }
}
diff --git a/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php
index c29f276596e..0cdefdf5a4b 100644
--- a/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php
+++ b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php
@@ -39,9 +39,11 @@ class TranscriptionFailedEvent extends AbstractTranscriptionEvent {
public function __construct(
int $fileId,
?File $file,
- private string $errorMessage
+ private string $errorMessage,
+ string $userId,
+ string $appId,
) {
- parent::__construct($fileId, $file);
+ parent::__construct($fileId, $file, $userId, $appId);
}
/**
diff --git a/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php
index 599e98a47be..79f379fca4d 100644
--- a/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php
+++ b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php
@@ -39,9 +39,11 @@ class TranscriptionSuccessfulEvent extends AbstractTranscriptionEvent {
public function __construct(
int $fileId,
?File $file,
- private string $transcript
+ private string $transcript,
+ string $userId,
+ string $appId,
) {
- parent::__construct($fileId, $file);
+ parent::__construct($fileId, $file, $userId, $appId);
}
/**
diff --git a/lib/public/SpeechToText/ISpeechToTextManager.php b/lib/public/SpeechToText/ISpeechToTextManager.php
index 9cf970d88ca..85ef299ae8e 100644
--- a/lib/public/SpeechToText/ISpeechToTextManager.php
+++ b/lib/public/SpeechToText/ISpeechToTextManager.php
@@ -46,11 +46,14 @@ interface ISpeechToTextManager {
* You should add context information to the context array to re-identify the transcription result as
* belonging to your transcription request.
*
+ * @param File $file The media file to transcribe
+ * @param string $userId The user that triggered this request (only for convenience, will be available on the TranscriptEvents)
+ * @param string $appId The app that triggered this request (only for convenience, will be available on the TranscriptEvents)
* @since 27.0.0
* @throws PreConditionNotMetException If no provider was registered but this method was still called
* @throws InvalidArgumentException If the file could not be found or is not of a supported type
*/
- public function scheduleFileTranscription(File $file): void;
+ public function scheduleFileTranscription(File $file, string $userId, string $appId): void;
/**
* @since 27.0.0