aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/SpeechToText
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-04-12 16:52:11 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-04-12 16:52:11 +0200
commitef7ce88cee47ec7d05c43e55c166f8488667dc5d (patch)
treee1e41af7d7b7a179297a3937c2d234b1193fc7bd /lib/private/SpeechToText
parent1833d932ef39bb77f59cee17f194fef7d768a67c (diff)
downloadnextcloud-server-ef7ce88cee47ec7d05c43e55c166f8488667dc5d.tar.gz
nextcloud-server-ef7ce88cee47ec7d05c43e55c166f8488667dc5d.zip
ISpeechToTextProvider#transcribeFile: Pass \OCP\Files\File instead of path
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/SpeechToText')
-rw-r--r--lib/private/SpeechToText/SpeechToTextManager.php24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php
index 2e1733d0e36..7b50fa385c9 100644
--- a/lib/private/SpeechToText/SpeechToTextManager.php
+++ b/lib/private/SpeechToText/SpeechToTextManager.php
@@ -31,6 +31,9 @@ namespace OC\SpeechToText;
use InvalidArgumentException;
use OC\AppFramework\Bootstrap\Coordinator;
use OCP\BackgroundJob\IJobList;
+use OCP\Files\File;
+use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\IServerContainer;
use OCP\PreConditionNotMetException;
use OCP\SpeechToText\ISpeechToTextManager;
@@ -49,6 +52,7 @@ class SpeechToTextManager implements ISpeechToTextManager {
private Coordinator $coordinator,
private LoggerInterface $logger,
private IJobList $jobList,
+ private IRootFolder $rootFolder,
) {
}
@@ -90,6 +94,14 @@ class SpeechToTextManager implements ISpeechToTextManager {
if (!$this->hasProviders()) {
throw new PreConditionNotMetException('No SpeechToText providers have been registered');
}
+ try {
+ $node = $this->rootFolder->get($path);
+ } catch (NotFoundException $e) {
+ throw new InvalidArgumentException('File does not exist: ' . $path);
+ }
+ if (!($node instanceof File)) {
+ throw new InvalidArgumentException('Path does not resolve to a file');
+ }
$this->jobList->add(TranscriptionJob::class, [ 'path' => $path, 'context' => $context]);
}
@@ -99,10 +111,14 @@ class SpeechToTextManager implements ISpeechToTextManager {
throw new PreConditionNotMetException('No SpeechToText providers have been registered');
}
- if (!file_exists($path)) {
- throw new InvalidArgumentException('File does not exist');
+ try {
+ $node = $this->rootFolder->get($path);
+ if (!($node instanceof File)) {
+ throw new InvalidArgumentException('Path does not resolve to a file');
+ }
+ return $provider->transcribeFile($node);
+ } catch (NotFoundException $e) {
+ throw new InvalidArgumentException('File does not exist: ' . $path);
}
-
- return $provider->transcribeFile($path);
}
}