Skip to content

Commit 71442ba

Browse files
authored
fix: 解决关闭公共聊天后访问后仍然可以聊天的问题 (#40)
1 parent 25d88f9 commit 71442ba

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/java/run/halo/live2d/chat/AiChatEndpoint.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,20 @@ private Mono<ServerResponse> chatProcess(ServerRequest request) {
8282
);
8383
}
8484

85+
8586
private Flux<ServerSentEvent<ChatResult>> chatCompletion(ChatRequest body) {
8687
return reactiveSettingFetcher.fetch("aichat", AiChatConfig.class)
87-
.doOnNext(aiChatConfig -> ReactiveSecurityContextHolder.getContext()
88+
.map(aiChatConfig -> ReactiveSecurityContextHolder.getContext()
8889
.map(SecurityContext::getAuthentication)
89-
.doOnNext(authentication -> {
90+
.flatMapMany(authentication -> {
9091
if (!aiChatConfig.aiChatBaseSetting.isAnonymous && !isAuthenticated(
9192
authentication)) {
9293
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "请先登录");
9394
}
95+
String systemMessage = aiChatConfig.aiChatBaseSetting.systemMessage;
96+
List<ChatMessage> messages = this.buildChatMessage(systemMessage, body);
97+
return aiChatService.streamChatCompletion(messages);
9498
}))
95-
.map(aiChatConfig -> {
96-
String systemMessage = aiChatConfig.aiChatBaseSetting.systemMessage;
97-
List<ChatMessage> messages = this.buildChatMessage(systemMessage, body);
98-
return aiChatService.streamChatCompletion(messages);
99-
})
10099
.flatMapMany(Flux::from);
101100
}
102101

0 commit comments

Comments
 (0)