Files
nl-admin-api/app/Http/Controllers/Api/AiConfigController.php
2026-08-10 15:51:00 +08:00

169 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Api;
use App\BaseApp\BaseController;
use App\Service\AiConfigService;
use Illuminate\Http\JsonResponse;
/**
* AI 配置控制器:运行时选用 + 密钥管理
*/
class AiConfigController extends BaseController
{
public function __construct()
{
parent::__construct();
$this->service = AiConfigService::getInstance();
}
/**
* 禁用基类通用列表(本模块用 keyList
* @Method NO
*/
public function list(): JsonResponse
{
return jerr('不支持');
}
/**
* @Method NO
*/
public function option(): mixed
{
return jerr('不支持');
}
/**
* @Method NO
*/
public function detail(): JsonResponse
{
return jerr('不支持');
}
/**
* @Method NO
*/
public function create(): JsonResponse
{
return jerr('不支持');
}
/**
* @Method NO
*/
public function update(): JsonResponse
{
return jerr('不支持');
}
/**
* @Method NO
*/
public function delete(): JsonResponse
{
return jerr('不支持');
}
/**
* 获取 AI 管理页选项(平台/模型/密钥卡片数据 + 当前激活项)
* @Method GET
*/
public function runtimeOptions(): JsonResponse
{
return jok($this->service->getRuntimeOptions(), '获取成功');
}
/**
* 保存默认 AI 平台/模型/密钥组合
* @Method POST
*/
public function saveRuntime(): JsonResponse
{
$params = request()->post();
return jok($this->service->saveRuntime($params), '保存成功');
}
/**
* 密钥列表(卡片展示)
* @Method GET
*/
public function keyList(): JsonResponse
{
return jok($this->service->listKeys(), '获取成功');
}
/**
* 平台下拉
* @Method GET
*/
public function platformOption(): JsonResponse
{
return jok($this->service->platformOptions(), '获取成功');
}
/**
* 新增密钥
* @Method POST
*/
public function createKey(): JsonResponse
{
$params = request()->post();
return jok($this->service->createKey($params), '创建成功');
}
/**
* 更新密钥
* @Method POST
*/
public function updateKey(): JsonResponse
{
$params = request()->post();
$id = (int) ($params['id'] ?? 0);
if ($id <= 0) {
return jerr('参数错误');
}
unset($params['id']);
return jok($this->service->updateKey($id, $params), '更新成功');
}
/**
* 删除密钥
* @Method POST
*/
public function deleteKey(): JsonResponse
{
$ids = request()->post('ids');
if (empty($ids)) {
return jerr('参数错误');
}
if (!is_array($ids)) {
$ids = [$ids];
}
return jok($this->service->deleteKeys($ids), '删除成功');
}
/**
* AI 生成历史列表
* @Method GET
*/
public function generationList(): JsonResponse
{
return jok($this->service->generationList(), '获取成功');
}
/**
* AI 生成历史详情
* @Method GET
*/
public function generationDetail(): JsonResponse
{
$id = (int) request()->get('id', 0);
if ($id <= 0) {
return jerr('参数错误');
}
return jok($this->service->generationDetail($id), '获取成功');
}
}