error(__('auth.failed'), null, 401); } if (! AiModelController::canEdit($user['user_uid'], $aiModel->owner_id)) { return $this->error(__('auth.failed'), null, 403); } $token = AuthService::getUserToken($aiModel->uid); if (! $token) { return $this->error('ai model not found', null, 404); } OpsLog::debug($user['user_uid'], [ 'action' => 'ai-model-token.issue', 'model_uid' => $aiModel->uid, 'model_name' => $aiModel->name, ]); return $this->ok([ 'uid' => $aiModel->uid, 'name' => $aiModel->name, 'token' => $token, ]); } /** * 撤销该模型已签出的全部身份 token。 * * 版本号自增后,旧 token 里的 ver 立即对不上(见 AuthService::current())。 * 无法只撤销其中一张——凭据泄漏时本就该全部作废。 */ public function destroy(Request $request, AiModel $aiModel): JsonResponse { $user = AuthService::current($request); if (! $user) { return $this->error(__('auth.failed'), null, 401); } if (! AiModelController::canEdit($user['user_uid'], $aiModel->owner_id)) { return $this->error(__('auth.failed'), null, 403); } $aiModel->increment('token_version'); OpsLog::debug($user['user_uid'], [ 'action' => 'ai-model-token.revoke', 'model_uid' => $aiModel->uid, 'model_name' => $aiModel->name, 'token_version' => (int) $aiModel->token_version, ]); return $this->ok([ 'uid' => $aiModel->uid, 'name' => $aiModel->name, 'token_version' => (int) $aiModel->token_version, ]); } }