gengx
This commit is contained in:
@@ -6,6 +6,7 @@ use app\model\AiModel;
|
||||
use app\model\Conversation as ConversationModel;
|
||||
use app\model\Message;
|
||||
use app\service\ComfyUIService;
|
||||
use app\service\GuestAccessService;
|
||||
use app\service\PermissionService;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
@@ -14,6 +15,12 @@ class Conversation extends BaseApi
|
||||
public function index()
|
||||
{
|
||||
$user = $this->authUser();
|
||||
if (GuestAccessService::isGuest($user)) {
|
||||
$guestModelId = GuestAccessService::modelId();
|
||||
$reset = ['model_id' => $guestModelId, 'external_conversation_id' => null];
|
||||
ConversationModel::where('user_id', $user['id'])->whereNull('deleted_at')->whereNull('model_id')->update($reset);
|
||||
ConversationModel::where('user_id', $user['id'])->whereNull('deleted_at')->where('model_id', '<>', $guestModelId)->update($reset);
|
||||
}
|
||||
$page = max(1, (int) $this->request->get('page', 1));
|
||||
$limit = min(50, max(1, (int) $this->request->get('limit', 20)));
|
||||
|
||||
@@ -51,6 +58,12 @@ class Conversation extends BaseApi
|
||||
$modelId = null;
|
||||
}
|
||||
|
||||
if (GuestAccessService::isGuest($user)) {
|
||||
$modelId = GuestAccessService::assertModelAllowed($user, $modelId);
|
||||
} elseif ($modelId && !AiModel::where('id', $modelId)->where('enabled', 1)->find()) {
|
||||
return $this->error('所选模型不存在或已停用', 422);
|
||||
}
|
||||
|
||||
$conversation = ConversationModel::create([
|
||||
'user_id' => $user['id'],
|
||||
'title' => trim($input['title'] ?? '新对话'),
|
||||
@@ -94,6 +107,13 @@ class Conversation extends BaseApi
|
||||
$data['model_id'] = (int) $mid;
|
||||
}
|
||||
|
||||
if (GuestAccessService::isGuest($user)) {
|
||||
$requestedModelId = $data['model_id'] ?: null;
|
||||
$data['model_id'] = GuestAccessService::assertModelAllowed($user, $requestedModelId);
|
||||
} elseif ($data['model_id'] && !AiModel::where('id', $data['model_id'])->where('enabled', 1)->find()) {
|
||||
return $this->error('所选模型不存在或已停用', 422);
|
||||
}
|
||||
|
||||
$currentModelId = $conversation->model_id === null
|
||||
? null
|
||||
: (int) $conversation->model_id;
|
||||
@@ -103,6 +123,14 @@ class Conversation extends BaseApi
|
||||
}
|
||||
}
|
||||
|
||||
if (GuestAccessService::isGuest($user) && !array_key_exists('model_id', $input)) {
|
||||
$guestModelId = GuestAccessService::modelId();
|
||||
if ((int) $conversation->model_id !== $guestModelId) {
|
||||
$data['model_id'] = $guestModelId;
|
||||
$data['external_conversation_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
return $this->error('无更新内容');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user