Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
public const LEGACY_PREFIX_TEXTTOIMAGE = 'legacy:TextToImage:';
public const LEGACY_PREFIX_SPEECHTOTEXT = 'legacy:SpeechToText:';

public const TASK_TYPES_CACHE_KEY = 'available_task_types_v3';

/** @var list<IProvider>|null */
private ?array $providers = null;

Expand Down Expand Up @@ -108,6 +110,7 @@
private IUserManager $userManager,
private IUserSession $userSession,
ICacheFactory $cacheFactory,
private IFactory $l10nFactory,
) {
$this->appData = $appDataFactory->get('core');
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
Expand Down Expand Up @@ -813,12 +816,15 @@
}

public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userId = null): array {
// We cache by language, because some task type fields are translated
$cacheKey = self::TASK_TYPES_CACHE_KEY . ':' . $this->l10nFactory->findLanguage();

// userId will be obtained from the session if left to null
if (!$this->checkGuestAccess($userId)) {
return [];
}
if ($this->availableTaskTypes === null) {
$cachedValue = $this->distributedCache->get('available_task_types_v2');
$cachedValue = $this->distributedCache->get($cacheKey);
if ($cachedValue !== null) {
$this->availableTaskTypes = unserialize($cachedValue);
}
Expand Down Expand Up @@ -864,7 +870,7 @@
}

$this->availableTaskTypes = $availableTaskTypes;
$this->distributedCache->set('available_task_types_v2', serialize($this->availableTaskTypes), 60);
$this->distributedCache->set($cacheKey, serialize($this->availableTaskTypes), 60);
}


Expand Down Expand Up @@ -1074,7 +1080,7 @@
$task->setEndedAt(time());
$error = 'The task was processed successfully but the provider\'s output doesn\'t pass validation against the task type\'s outputShape spec and/or the provider\'s own optionalOutputShape spec';
$task->setErrorMessage($error);
$this->logger->error($error . ' Output was: ' . var_export($result, true), ['exception' => $e]);

Check failure on line 1083 in lib/private/TaskProcessing/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedHtml

lib/private/TaskProcessing/Manager.php:1083:64: TaintedHtml: Detected tainted HTML (see https://psalm.dev/245)
} catch (NotPermittedException $e) {
$task->setProgress(1);
$task->setStatus(Task::STATUS_FAILED);
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -28,6 +29,7 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\Events\GetTaskProcessingProvidersEvent;
use OCP\TaskProcessing\Events\TaskFailedEvent;
Expand Down Expand Up @@ -612,6 +614,7 @@ protected function setUp(): void {
$userManager,
\OC::$server->get(IUserSession::class),
\OC::$server->get(ICacheFactory::class),
\OC::$server->get(IFactory::class),
);
}

Expand Down Expand Up @@ -1264,6 +1267,7 @@ private function createManagerInstance(): Manager {
\OC::$server->get(IUserManager::class),
\OC::$server->get(IUserSession::class),
\OC::$server->get(ICacheFactory::class),
\OC::$server->get(IFactory::class),
);
}

Expand Down
Loading