You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
namespace Isekai\AIToolbox\Job;
|
|
|
|
use Job;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\Context\RequestContext;
|
|
use MediaWiki\Title\Title;
|
|
use MediaWiki\Status\Status;
|
|
|
|
class UpdateTitleIndexJob extends Job {
|
|
public function __construct(Title $title) {
|
|
parent::__construct('isekaiAIUpdateTitleIndex', $title);
|
|
}
|
|
|
|
/**
|
|
* 触发AI后端更新标题索引
|
|
*/
|
|
public function run() {
|
|
$services = MediaWikiServices::getInstance();
|
|
$config = $services->getMainConfig();
|
|
$context = RequestContext::getMain();
|
|
|
|
$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', [
|
|
'method' => 'POST',
|
|
'postData' => [
|
|
'title' => $pageTitle
|
|
],
|
|
'timeout' => 20
|
|
], __METHOD__);
|
|
|
|
$req->setHeader('Authorization', 'Bearer ' . $authToken);
|
|
|
|
$status = Status::wrap($req->execute());
|
|
if (!$status->isOK()) {
|
|
$formatterFactory = MediaWikiServices::getInstance()->getFormatterFactory();
|
|
$formatter = $formatterFactory->getStatusFormatter($context);
|
|
$this->setLastError($formatter->getMessage($status));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |