diff --git a/extension.json b/extension.json index eb52af4..0bd70da 100644 --- a/extension.json +++ b/extension.json @@ -16,33 +16,33 @@ ] }, "GroupPermissions": { - "user": { + "user": { "ccembeddingpage": true, - "chatcomplete": true - }, + "chatcomplete": true + }, "sysop": { "aitoolbox-unlimited": true, - "chatcomplete": true, + "chatcomplete": true, "aitoolboxbot": true } - }, - "GrantPermissions": { + }, + "GrantPermissions": { "aitoolboxbot": { "ccembeddingpage": true, - "chatcomplete": true, + "chatcomplete": true, "aitoolboxbot": true, "aitoolbox-unlimited": true } - }, - "AvailableRights": [ - "chatcomplete", + }, + "AvailableRights": [ + "chatcomplete", "ccembeddingpage", "aitoolboxbot", "aitoolbox-unlimited" - ], - "GrantPermissionGroups": { + ], + "GrantPermissionGroups": { "aitoolboxbot": "aitoolboxbot" - }, + }, "AutoloadNamespaces": { "Isekai\\AIToolbox\\": "includes" }, @@ -50,20 +50,23 @@ "LoadExtensionSchemaUpdates": [ "Isekai\\AIToolbox\\Hooks::onLoadExtensionSchemaUpdates" ], - "BeforePageDisplay": [ + "BeforePageDisplay": [ "Isekai\\AIToolbox\\Hooks::onLoad" ], - "ResourceLoaderGetConfigVars": [ - "Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars" - ], - "onPageSaveComplete": [ - "Isekai\\AIToolbox\\Hooks::onPageSaveComplete" - ] + "ResourceLoaderGetConfigVars": [ + "Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars" + ], + "PageSaveComplete": [ + "Isekai\\AIToolbox\\Hooks::onPageSaveComplete" + ] }, "APIModules": { "aitoolbox": "Isekai\\AIToolbox\\Api\\ApiAIToolbox", "aitoolboxbot": "Isekai\\AIToolbox\\Api\\ApiAIToolboxBot" }, + "JobClasses": { + "isekaiAIUpdateTitleIndex": "Isekai\\AIToolbox\\Job\\UpdateTitleIndexJob" + }, "ResourceModules": { "ext.isekai.ai-toolbox.launcher": { "scripts": [ @@ -72,7 +75,7 @@ "styles": [], "dependencies": [ "ext.isekai.baseWidgets", - "oojs-ui.styles.icons-content" + "oojs-ui.styles.icons-content" ], "targets": [ "desktop", @@ -110,6 +113,6 @@ "value": "/ai-toolbox/toolbox/{title}?token={token}" } }, - "load_composer_autoloader": true, + "load_composer_autoloader": true, "manifest_version": 2 } \ No newline at end of file diff --git a/includes/Hooks.php b/includes/Hooks.php index 25203aa..7609d06 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -39,8 +39,9 @@ class Hooks { */ public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) { $title = $wikiPage->getTitle(); - if ($title && $title->exists() && $title->getNamespace() === NS_MAIN) { - $job = new UpdateTitleIndexJob($wikiPage->getTitle(), []); + if ($title && $title->inNamespace(NS_MAIN)) { + wfDebug('[IsekaiAIToolbox] push UpdateTitleIndexJob'); + $job = new UpdateTitleIndexJob($wikiPage->getTitle()); MediaWikiServices::getInstance()->getJobQueueGroup()->push($job); } } diff --git a/includes/Job/UpdateTitleIndexJob.php b/includes/Job/UpdateTitleIndexJob.php index b9815a1..2e0eca1 100644 --- a/includes/Job/UpdateTitleIndexJob.php +++ b/includes/Job/UpdateTitleIndexJob.php @@ -6,8 +6,8 @@ use MediaWiki\MediaWikiServices; use Title; class UpdateTitleIndexJob extends Job { - public function __construct(Title $title, array $params){ - parent::__construct('IsekaiAIUpdateTitleIndex', $title, $params); + public function __construct(Title $title) { + parent::__construct('isekaiAIUpdateTitleIndex', $title); } /** @@ -17,20 +17,29 @@ class UpdateTitleIndexJob extends Job { $services = MediaWikiServices::getInstance(); $config = $services->getMainConfig(); - $endpoint = $config->get('wgIsekaiAIBackendEndpoint'); + $endpoint = $config->get('IsekaiAIBackendEndpoint'); + $authToken = $config->get('IsekaiAIToolboxToken'); $title = $this->title; $pageTitle = $title->getText(); $factory = MediaWikiServices::getInstance()->getHttpRequestFactory(); - $req = $factory->create($endpoint + '/sys/embedding_search/title/update', [ + $req = $factory->create($endpoint . '/sys/embedding_search/title/update', [ 'method' => 'POST', 'postData' => [ 'title' => $pageTitle ], - 'timeout' => 10 + 'timeout' => 20 ], __METHOD__); + $req->setHeader('Authorization', 'Bearer ' . $authToken); + + $status = \Status::wrap($req->execute()); + if(!$status->isOK()){ + $this->setLastError($status->getMessage()); + return false; + } + return true; } } \ No newline at end of file