mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat: add fake OCR taskprocessing provider in the testing app
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
72ad2edcd7
commit
e1d19b2c24
4 changed files with 97 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ return array(
|
|||
'OCA\\Testing\\Provider\\FakeTranslationProvider' => $baseDir . '/../lib/Provider/FakeTranslationProvider.php',
|
||||
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => $baseDir . '/../lib/Settings/DeclarativeSettingsForm.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => $baseDir . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeOcrProvider' => $baseDir . '/../lib/TaskProcessing/FakeOcrProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class ComposerStaticInitTesting
|
|||
'OCA\\Testing\\Provider\\FakeTranslationProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTranslationProvider.php',
|
||||
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => __DIR__ . '/..' . '/../lib/Settings/DeclarativeSettingsForm.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeOcrProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeOcrProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use OCA\Testing\Provider\FakeTextProcessingProviderSync;
|
|||
use OCA\Testing\Provider\FakeTranslationProvider;
|
||||
use OCA\Testing\Settings\DeclarativeSettingsForm;
|
||||
use OCA\Testing\TaskProcessing\FakeContextWriteProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeOcrProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToImageProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToTextChatProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToTextProvider;
|
||||
|
|
@ -54,6 +55,7 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerTaskProcessingProvider(FakeTranslateProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeTranscribeProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeContextWriteProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeOcrProvider::class);
|
||||
|
||||
$context->registerFileConversionProvider(ConversionProvider::class);
|
||||
|
||||
|
|
|
|||
93
apps/testing/lib/TaskProcessing/FakeOcrProvider.php
Normal file
93
apps/testing/lib/TaskProcessing/FakeOcrProvider.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Testing\TaskProcessing;
|
||||
|
||||
use OCA\Testing\AppInfo\Application;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\Files\File;
|
||||
use OCP\TaskProcessing\Exception\ProcessingException;
|
||||
use OCP\TaskProcessing\ISynchronousProvider;
|
||||
use OCP\TaskProcessing\TaskTypes\ImageToTextOpticalCharacterRecognition;
|
||||
use RuntimeException;
|
||||
|
||||
class FakeOcrProvider implements ISynchronousProvider {
|
||||
|
||||
public function __construct(
|
||||
protected IAppConfig $appConfig,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
return Application::APP_ID . '-image2text-ocr';
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Fake OCR task processing provider';
|
||||
}
|
||||
|
||||
public function getTaskTypeId(): string {
|
||||
return ImageToTextOpticalCharacterRecognition::ID;
|
||||
}
|
||||
|
||||
public function getExpectedRuntime(): int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getInputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getInputShapeDefaults(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShape(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShapeDefaults(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOutputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalOutputShape(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalOutputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function process(?string $userId, array $input, callable $reportProgress): array {
|
||||
if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
|
||||
throw new ProcessingException('Failing as set by AppConfig');
|
||||
}
|
||||
|
||||
if (!isset($input['input']) || !is_array($input['input'])) {
|
||||
throw new RuntimeException('Invalid input');
|
||||
}
|
||||
$outputs = [];
|
||||
foreach ($input['input'] as $i => $inputImage) {
|
||||
if (!($inputImage instanceof File) || !$inputImage->isReadable()) {
|
||||
throw new RuntimeException('Invalid input images');
|
||||
}
|
||||
$outputs[] = '[' . $i . '] This is a fake OCR result.';
|
||||
}
|
||||
|
||||
return ['output' => $outputs];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue