增加主动更新标题索引功能

main
落雨楓 2 years ago
parent cec2ca565d
commit a2ec580fef

@ -16,33 +16,33 @@
] ]
}, },
"GroupPermissions": { "GroupPermissions": {
"user": { "user": {
"ccembeddingpage": true, "ccembeddingpage": true,
"chatcomplete": true "chatcomplete": true
}, },
"sysop": { "sysop": {
"aitoolbox-unlimited": true, "aitoolbox-unlimited": true,
"chatcomplete": true, "chatcomplete": true,
"aitoolboxbot": true "aitoolboxbot": true
} }
}, },
"GrantPermissions": { "GrantPermissions": {
"aitoolboxbot": { "aitoolboxbot": {
"ccembeddingpage": true, "ccembeddingpage": true,
"chatcomplete": true, "chatcomplete": true,
"aitoolboxbot": true, "aitoolboxbot": true,
"aitoolbox-unlimited": true "aitoolbox-unlimited": true
} }
}, },
"AvailableRights": [ "AvailableRights": [
"chatcomplete", "chatcomplete",
"ccembeddingpage", "ccembeddingpage",
"aitoolboxbot", "aitoolboxbot",
"aitoolbox-unlimited" "aitoolbox-unlimited"
], ],
"GrantPermissionGroups": { "GrantPermissionGroups": {
"aitoolboxbot": "aitoolboxbot" "aitoolboxbot": "aitoolboxbot"
}, },
"AutoloadNamespaces": { "AutoloadNamespaces": {
"Isekai\\AIToolbox\\": "includes" "Isekai\\AIToolbox\\": "includes"
}, },
@ -50,20 +50,23 @@
"LoadExtensionSchemaUpdates": [ "LoadExtensionSchemaUpdates": [
"Isekai\\AIToolbox\\Hooks::onLoadExtensionSchemaUpdates" "Isekai\\AIToolbox\\Hooks::onLoadExtensionSchemaUpdates"
], ],
"BeforePageDisplay": [ "BeforePageDisplay": [
"Isekai\\AIToolbox\\Hooks::onLoad" "Isekai\\AIToolbox\\Hooks::onLoad"
], ],
"ResourceLoaderGetConfigVars": [ "ResourceLoaderGetConfigVars": [
"Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars" "Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars"
], ],
"onPageSaveComplete": [ "PageSaveComplete": [
"Isekai\\AIToolbox\\Hooks::onPageSaveComplete" "Isekai\\AIToolbox\\Hooks::onPageSaveComplete"
] ]
}, },
"APIModules": { "APIModules": {
"aitoolbox": "Isekai\\AIToolbox\\Api\\ApiAIToolbox", "aitoolbox": "Isekai\\AIToolbox\\Api\\ApiAIToolbox",
"aitoolboxbot": "Isekai\\AIToolbox\\Api\\ApiAIToolboxBot" "aitoolboxbot": "Isekai\\AIToolbox\\Api\\ApiAIToolboxBot"
}, },
"JobClasses": {
"isekaiAIUpdateTitleIndex": "Isekai\\AIToolbox\\Job\\UpdateTitleIndexJob"
},
"ResourceModules": { "ResourceModules": {
"ext.isekai.ai-toolbox.launcher": { "ext.isekai.ai-toolbox.launcher": {
"scripts": [ "scripts": [
@ -72,7 +75,7 @@
"styles": [], "styles": [],
"dependencies": [ "dependencies": [
"ext.isekai.baseWidgets", "ext.isekai.baseWidgets",
"oojs-ui.styles.icons-content" "oojs-ui.styles.icons-content"
], ],
"targets": [ "targets": [
"desktop", "desktop",
@ -110,6 +113,6 @@
"value": "/ai-toolbox/toolbox/{title}?token={token}" "value": "/ai-toolbox/toolbox/{title}?token={token}"
} }
}, },
"load_composer_autoloader": true, "load_composer_autoloader": true,
"manifest_version": 2 "manifest_version": 2
} }

@ -39,8 +39,9 @@ class Hooks {
*/ */
public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) { public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) {
$title = $wikiPage->getTitle(); $title = $wikiPage->getTitle();
if ($title && $title->exists() && $title->getNamespace() === NS_MAIN) { if ($title && $title->inNamespace(NS_MAIN)) {
$job = new UpdateTitleIndexJob($wikiPage->getTitle(), []); wfDebug('[IsekaiAIToolbox] push UpdateTitleIndexJob');
$job = new UpdateTitleIndexJob($wikiPage->getTitle());
MediaWikiServices::getInstance()->getJobQueueGroup()->push($job); MediaWikiServices::getInstance()->getJobQueueGroup()->push($job);
} }
} }

@ -6,8 +6,8 @@ use MediaWiki\MediaWikiServices;
use Title; use Title;
class UpdateTitleIndexJob extends Job { class UpdateTitleIndexJob extends Job {
public function __construct(Title $title, array $params){ public function __construct(Title $title) {
parent::__construct('IsekaiAIUpdateTitleIndex', $title, $params); parent::__construct('isekaiAIUpdateTitleIndex', $title);
} }
/** /**
@ -17,20 +17,29 @@ class UpdateTitleIndexJob extends Job {
$services = MediaWikiServices::getInstance(); $services = MediaWikiServices::getInstance();
$config = $services->getMainConfig(); $config = $services->getMainConfig();
$endpoint = $config->get('wgIsekaiAIBackendEndpoint'); $endpoint = $config->get('IsekaiAIBackendEndpoint');
$authToken = $config->get('IsekaiAIToolboxToken');
$title = $this->title; $title = $this->title;
$pageTitle = $title->getText(); $pageTitle = $title->getText();
$factory = MediaWikiServices::getInstance()->getHttpRequestFactory(); $factory = MediaWikiServices::getInstance()->getHttpRequestFactory();
$req = $factory->create($endpoint + '/sys/embedding_search/title/update', [ $req = $factory->create($endpoint . '/sys/embedding_search/title/update', [
'method' => 'POST', 'method' => 'POST',
'postData' => [ 'postData' => [
'title' => $pageTitle 'title' => $pageTitle
], ],
'timeout' => 10 'timeout' => 20
], __METHOD__); ], __METHOD__);
$req->setHeader('Authorization', 'Bearer ' . $authToken);
$status = \Status::wrap($req->execute());
if(!$status->isOK()){
$this->setLastError($status->getMessage());
return false;
}
return true; return true;
} }
} }
Loading…
Cancel
Save