diff --git a/appinfo/routes.php b/appinfo/routes.php index 887d1841..0c1c6936 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -11,6 +11,7 @@ ['name' => 'config#setAdminConfig', 'url' => '/admin-config', 'verb' => 'PUT'], ['name' => 'assistant#getAssistantTaskResultPage', 'url' => '/task/view/{metaTaskId}', 'verb' => 'GET'], + ['name' => 'assistant#getAssistantStandalonePage', 'url' => '/', 'verb' => 'GET'], ['name' => 'Text2Image#showGenerationPage', 'url' => '/i/{imageGenId}', 'verb' => 'GET'], ['name' => 'Text2Image#getPromptHistory', 'url' => '/i/data/prompt_history', 'verb' => 'GET'], diff --git a/lib/Controller/AssistantController.php b/lib/Controller/AssistantController.php index 4b68b0a8..14205fb6 100644 --- a/lib/Controller/AssistantController.php +++ b/lib/Controller/AssistantController.php @@ -3,6 +3,7 @@ namespace OCA\Assistant\Controller; use OCA\Assistant\AppInfo\Application; +use OCA\Assistant\Db\MetaTask; use OCA\Assistant\Service\AssistantService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -11,6 +12,7 @@ use OCP\AppFramework\Http\Attribute\OpenAPI; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; +use OCP\IConfig; use OCP\IRequest; #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] @@ -21,6 +23,7 @@ public function __construct( IRequest $request, private AssistantService $assistantService, private IInitialState $initialStateService, + private IConfig $config, private ?string $userId, ) { parent::__construct($appName, $request); @@ -37,9 +40,28 @@ public function getAssistantTaskResultPage(int $metaTaskId): TemplateResponse { $task = $this->assistantService->getAssistantTask($this->userId, $metaTaskId); if ($task !== null) { $this->initialStateService->provideInitialState('task', $task->jsonSerializeCc()); - return new TemplateResponse(Application::APP_ID, 'taskResultPage'); + return new TemplateResponse(Application::APP_ID, 'assistantPage'); } } return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN); } + + /** + * @return TemplateResponse + */ + #[NoAdminRequired] + #[NoCSRFRequired] + public function getAssistantStandalonePage(): TemplateResponse { + if ($this->userId !== null) { + $task = new MetaTask(); + $task->setTaskType($this->config->getUserValue($this->userId, Application::APP_ID, 'last_task_type')); + $task->setUserId($this->userId); + $task->setAppId(Application::APP_ID); + $task->setInputs('{"prompt":""}'); + $task->setIdentifier(''); + $this->initialStateService->provideInitialState('task', $task->jsonSerializeCc()); + return new TemplateResponse(Application::APP_ID, 'assistantPage'); + } + return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN); + } } diff --git a/lib/Db/MetaTask.php b/lib/Db/MetaTask.php index 3f82616f..06289479 100644 --- a/lib/Db/MetaTask.php +++ b/lib/Db/MetaTask.php @@ -103,6 +103,9 @@ public function jsonSerializeCc() { * @return array */ public function getInputsAsArray(): array { + if ($this->inputs === null) { + return []; + } return json_decode($this->inputs, true) ?? []; } } diff --git a/src/assistantPage.js b/src/assistantPage.js new file mode 100644 index 00000000..d77d4953 --- /dev/null +++ b/src/assistantPage.js @@ -0,0 +1,6 @@ +import Vue from 'vue' +import AssistantPage from './views/AssistantPage.vue' +Vue.mixin({ methods: { t, n } }) + +const View = Vue.extend(AssistantPage) +new View().$mount('#content') diff --git a/src/taskResultPage.js b/src/taskResultPage.js deleted file mode 100644 index 19908b53..00000000 --- a/src/taskResultPage.js +++ /dev/null @@ -1,6 +0,0 @@ -import Vue from 'vue' -import TaskResultPage from './views/TaskResultPage.vue' -Vue.mixin({ methods: { t, n } }) - -const View = Vue.extend(TaskResultPage) -new View().$mount('#content') diff --git a/src/views/TaskResultPage.vue b/src/views/AssistantPage.vue similarity index 97% rename from src/views/TaskResultPage.vue rename to src/views/AssistantPage.vue index 85264f35..43451b90 100644 --- a/src/views/TaskResultPage.vue +++ b/src/views/AssistantPage.vue @@ -1,8 +1,7 @@