aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/AppConfig.php2
-rw-r--r--lib/private/Files/Mount/MoveableMount.php4
-rw-r--r--lib/private/Files/ObjectStore/S3.php2
-rw-r--r--lib/private/Files/Storage/Local.php19
-rw-r--r--lib/private/SpeechToText/SpeechToTextManager.php15
-rw-r--r--lib/private/TextProcessing/Db/TaskMapper.php2
-rw-r--r--lib/private/TextProcessing/Manager.php18
-rw-r--r--lib/private/Translation/TranslationManager.php25
-rw-r--r--lib/private/legacy/OC_Helper.php31
9 files changed, 92 insertions, 26 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php
index 96fa6bf7467..84f0d5b9e5a 100644
--- a/lib/private/AppConfig.php
+++ b/lib/private/AppConfig.php
@@ -175,7 +175,7 @@ class AppConfig implements IAppConfig {
/**
* Get all apps using the config
*
- * @return array an array of app ids
+ * @return string[] an array of app ids
*
* This function returns a list of all apps that have at least one
* entry in the appconfig table.
diff --git a/lib/private/Files/Mount/MoveableMount.php b/lib/private/Files/Mount/MoveableMount.php
index a7372153d75..7dbed24504e 100644
--- a/lib/private/Files/Mount/MoveableMount.php
+++ b/lib/private/Files/Mount/MoveableMount.php
@@ -22,10 +22,12 @@
*/
namespace OC\Files\Mount;
+use OCP\Files\Mount\IMovableMount;
+
/**
* Defines the mount point to be (re)moved by the user
*/
-interface MoveableMount {
+interface MoveableMount extends IMovableMount {
/**
* Move the mount point to $target
*
diff --git a/lib/private/Files/ObjectStore/S3.php b/lib/private/Files/ObjectStore/S3.php
index 2d9119b5fc6..b1cd89388ae 100644
--- a/lib/private/Files/ObjectStore/S3.php
+++ b/lib/private/Files/ObjectStore/S3.php
@@ -99,7 +99,7 @@ class S3 implements IObjectStore, IObjectStoreMultiPartUpload {
$stat = $this->getConnection()->headObject([
'Bucket' => $this->bucket,
'Key' => $urn,
- ]);
+ ] + $this->getSSECParameters());
return (int)$stat->get('ContentLength');
}
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php
index c0ce0e7021a..fb62a53d894 100644
--- a/lib/private/Files/Storage/Local.php
+++ b/lib/private/Files/Storage/Local.php
@@ -335,7 +335,7 @@ class Local extends \OC\Files\Storage\Common {
}
}
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
$srcParent = dirname($source);
$dstParent = dirname($target);
@@ -361,21 +361,14 @@ class Local extends \OC\Files\Storage\Common {
}
if ($this->is_dir($source)) {
- // we can't move folders across devices, use copy instead
- $stat1 = stat(dirname($this->getSourcePath($source)));
- $stat2 = stat(dirname($this->getSourcePath($target)));
- if ($stat1['dev'] !== $stat2['dev']) {
- $result = $this->copy($source, $target);
- if ($result) {
- $result &= $this->rmdir($source);
- }
- return $result;
- }
-
$this->checkTreeForForbiddenItems($this->getSourcePath($source));
}
- return rename($this->getSourcePath($source), $this->getSourcePath($target));
+ if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {
+ return true;
+ }
+
+ return $this->copy($source, $target) && $this->rmdir($source);
}
public function copy($source, $target) {
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php
index 757fc02485e..bdd04ad3651 100644
--- a/lib/private/SpeechToText/SpeechToTextManager.php
+++ b/lib/private/SpeechToText/SpeechToTextManager.php
@@ -34,6 +34,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\Files\File;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
+use OCP\IConfig;
use OCP\IServerContainer;
use OCP\PreConditionNotMetException;
use OCP\SpeechToText\ISpeechToTextManager;
@@ -53,6 +54,7 @@ class SpeechToTextManager implements ISpeechToTextManager {
private Coordinator $coordinator,
private LoggerInterface $logger,
private IJobList $jobList,
+ private IConfig $config,
) {
}
@@ -111,7 +113,18 @@ class SpeechToTextManager implements ISpeechToTextManager {
throw new PreConditionNotMetException('No SpeechToText providers have been registered');
}
- foreach ($this->getProviders() as $provider) {
+ $providers = $this->getProviders();
+
+ $json = $this->config->getAppValue('core', 'ai.stt_provider', '');
+ if ($json !== '') {
+ $className = json_decode($json, true);
+ $provider = current(array_filter($providers, fn ($provider) => $provider::class === $className));
+ if ($provider !== false) {
+ $providers = [$provider];
+ }
+ }
+
+ foreach ($providers as $provider) {
try {
return $provider->transcribeFile($file);
} catch (\Throwable $e) {
diff --git a/lib/private/TextProcessing/Db/TaskMapper.php b/lib/private/TextProcessing/Db/TaskMapper.php
index 508f3fdf3b8..624efd042f7 100644
--- a/lib/private/TextProcessing/Db/TaskMapper.php
+++ b/lib/private/TextProcessing/Db/TaskMapper.php
@@ -41,7 +41,7 @@ class TaskMapper extends QBMapper {
IDBConnection $db,
private ITimeFactory $timeFactory,
) {
- parent::__construct($db, 'llm_tasks', Task::class);
+ parent::__construct($db, 'textprocessing_tasks', Task::class);
}
/**
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php
index f52482bbb32..05e046a0049 100644
--- a/lib/private/TextProcessing/Manager.php
+++ b/lib/private/TextProcessing/Manager.php
@@ -27,6 +27,7 @@ namespace OC\TextProcessing;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\TextProcessing\Db\Task as DbTask;
+use OCP\IConfig;
use OCP\TextProcessing\Task as OCPTask;
use OC\TextProcessing\Db\TaskMapper;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -52,6 +53,7 @@ class Manager implements IManager {
private LoggerInterface $logger,
private IJobList $jobList,
private TaskMapper $taskMapper,
+ private IConfig $config,
) {
}
@@ -111,7 +113,21 @@ class Manager implements IManager {
if (!$this->canHandleTask($task)) {
throw new PreConditionNotMetException('No text processing provider is installed that can handle this task');
}
- foreach ($this->getProviders() as $provider) {
+ $providers = $this->getProviders();
+ $json = $this->config->getAppValue('core', 'ai.textprocessing_provider_preferences', '');
+ if ($json !== '') {
+ $preferences = json_decode($json, true);
+ if (isset($preferences[$task->getType()])) {
+ // If a preference for this task type is set, move the preferred provider to the start
+ $provider = current(array_filter($providers, fn ($provider) => $provider::class === $preferences[$task->getType()]));
+ if ($provider !== false) {
+ $providers = array_filter($providers, fn ($p) => $p !== $provider);
+ array_unshift($providers, $provider);
+ }
+ }
+ }
+
+ foreach ($providers as $provider) {
if (!$task->canUseProvider($provider)) {
continue;
}
diff --git a/lib/private/Translation/TranslationManager.php b/lib/private/Translation/TranslationManager.php
index 8456c41cdfc..48a0e2cdebd 100644
--- a/lib/private/Translation/TranslationManager.php
+++ b/lib/private/Translation/TranslationManager.php
@@ -28,6 +28,7 @@ namespace OC\Translation;
use InvalidArgumentException;
use OC\AppFramework\Bootstrap\Coordinator;
+use OCP\IConfig;
use OCP\IServerContainer;
use OCP\PreConditionNotMetException;
use OCP\Translation\CouldNotTranslateException;
@@ -48,6 +49,7 @@ class TranslationManager implements ITranslationManager {
private IServerContainer $serverContainer,
private Coordinator $coordinator,
private LoggerInterface $logger,
+ private IConfig $config,
) {
}
@@ -64,8 +66,25 @@ class TranslationManager implements ITranslationManager {
throw new PreConditionNotMetException('No translation providers available');
}
+ $providers = $this->getProviders();
+ $json = $this->config->getAppValue('core', 'ai.translation_provider_preferences', '');
+
+ if ($json !== '') {
+ $precedence = json_decode($json, true);
+ $newProviders = [];
+ foreach ($precedence as $className) {
+ $provider = current(array_filter($providers, fn ($provider) => $provider::class === $className));
+ if ($provider !== false) {
+ $newProviders[] = $provider;
+ }
+ }
+ // Add all providers that haven't been added so far
+ $newProviders += array_udiff($providers, $newProviders, fn ($a, $b) => $a::class > $b::class ? 1 : ($a::class < $b::class ? -1 : 0));
+ $providers = $newProviders;
+ }
+
if ($fromLanguage === null) {
- foreach ($this->getProviders() as $provider) {
+ foreach ($providers as $provider) {
if ($provider instanceof IDetectLanguageProvider) {
$fromLanguage = $provider->detectLanguage($text);
}
@@ -84,11 +103,11 @@ class TranslationManager implements ITranslationManager {
return $text;
}
- foreach ($this->getProviders() as $provider) {
+ foreach ($providers as $provider) {
try {
return $provider->translate($fromLanguage, $toLanguage, $text);
} catch (RuntimeException $e) {
- $this->logger->warning("Failed to translate from {$fromLanguage} to {$toLanguage}", ['exception' => $e]);
+ $this->logger->warning("Failed to translate from {$fromLanguage} to {$toLanguage} using provider {$provider->getName()}", ['exception' => $e]);
}
}
diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php
index 8c8be0e1069..d96cb7bb4e9 100644
--- a/lib/private/legacy/OC_Helper.php
+++ b/lib/private/legacy/OC_Helper.php
@@ -54,6 +54,18 @@ use Psr\Log\LoggerInterface;
/**
* Collection of useful functions
+ *
+ * @psalm-type StorageInfo = array{
+ * free: float|int,
+ * mountPoint: string,
+ * mountType: string,
+ * owner: string,
+ * ownerDisplayName: string,
+ * quota: float|int,
+ * relative: float|int,
+ * total: float|int,
+ * used: float|int,
+ * }
*/
class OC_Helper {
private static $templateManager;
@@ -458,7 +470,8 @@ class OC_Helper {
* @param \OCP\Files\FileInfo $rootInfo (optional)
* @param bool $includeMountPoints whether to include mount points in the size calculation
* @param bool $useCache whether to use the cached quota values
- * @return array
+ * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct
+ * @return StorageInfo
* @throws \OCP\Files\NotFoundException
*/
public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) {
@@ -491,8 +504,9 @@ class OC_Helper {
}
$used = $rootInfo->getSize($includeMountPoints);
if ($used < 0) {
- $used = 0;
+ $used = 0.0;
}
+ /** @var int|float $quota */
$quota = \OCP\Files\FileInfo::SPACE_UNLIMITED;
$mount = $rootInfo->getMountPoint();
$storage = $mount->getStorage();
@@ -523,6 +537,9 @@ class OC_Helper {
}
try {
$free = $sourceStorage->free_space($rootInfo->getInternalPath());
+ if (is_bool($free)) {
+ $free = 0.0;
+ }
} catch (\Exception $e) {
if ($path === "") {
throw $e;
@@ -549,6 +566,7 @@ class OC_Helper {
$relative = 0;
}
+ /** @var string $ownerId */
$ownerId = $storage->getOwner($path);
$ownerDisplayName = '';
if ($ownerId) {
@@ -580,15 +598,20 @@ class OC_Helper {
/**
* Get storage info including all mount points and quota
+ *
+ * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct
+ * @return StorageInfo
*/
private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMountPoint $mount): array {
$rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext');
+ /** @var int|float $used */
$used = $rootInfo['size'];
if ($used < 0) {
- $used = 0;
+ $used = 0.0;
}
$total = $quota;
+ /** @var int|float $free */
$free = $quota - $used;
if ($total > 0) {
@@ -598,7 +621,7 @@ class OC_Helper {
// prevent division by zero or error codes (negative values)
$relative = round(($used / $total) * 10000) / 100;
} else {
- $relative = 0;
+ $relative = 0.0;
}
if (substr_count($mount->getMountPoint(), '/') < 3) {