Skip to content

Commit e55a8b4

Browse files
committed
feat: convert from processors to custom API and enable streaming when using server execution
1 parent d21cbf6 commit e55a8b4

File tree

26 files changed

+814
-736
lines changed

26 files changed

+814
-736
lines changed

assets/components/modai/api.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
require_once dirname(__DIR__, 3) . '/config.core.php';
3+
require_once MODX_CORE_PATH . 'vendor/autoload.php';
4+
5+
$modx = new \MODX\Revolution\modX();
6+
$modx->initialize('mgr');
7+
8+
$request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
9+
$action = $modx->getOption('action', $_REQUEST, '');
10+
11+
if (empty($action)) {
12+
\modAI\API\API::returnErrorFromAPIException(\modAI\API\APIException::badRequest());
13+
exit;
14+
}
15+
16+
$action = str_replace('/', '\\', $action);
17+
18+
$className = "\\modAI\\API\\$action";
19+
if (class_exists($className) !== true) {
20+
\modAI\API\API::returnErrorFromAPIException(\modAI\API\APIException::notFound());
21+
exit;
22+
}
23+
24+
$ajaxEndpoint = new $className($modx);
25+
$ajaxEndpoint->handleRequest($request);
26+
27+
exit;

0 commit comments

Comments
 (0)