mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-15 20:08:18 +08:00
fix(chat): return 403 not 500 for conversation access failures
This commit is contained in:
parent
85f1e326ed
commit
401c413a77
@ -56,7 +56,7 @@ public class ConversationController {
|
|||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权访问该会话");
|
return R.fail(403, "无权访问该会话");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向后兼容:不传 limit 则返回全部消息(旧前端行为)
|
// 向后兼容:不传 limit 则返回全部消息(旧前端行为)
|
||||||
@ -101,7 +101,7 @@ public class ConversationController {
|
|||||||
public R<Void> delete(@PathVariable String conversationId, Authentication auth) {
|
public R<Void> delete(@PathVariable String conversationId, Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权操作该会话");
|
return R.fail(403, "无权操作该会话");
|
||||||
}
|
}
|
||||||
conversationService.deleteConversation(conversationId);
|
conversationService.deleteConversation(conversationId);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@ -115,7 +115,7 @@ public class ConversationController {
|
|||||||
public R<Void> rename(@PathVariable String conversationId, @RequestBody Map<String, String> body, Authentication auth) {
|
public R<Void> rename(@PathVariable String conversationId, @RequestBody Map<String, String> body, Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权操作该会话");
|
return R.fail(403, "无权操作该会话");
|
||||||
}
|
}
|
||||||
String title = body.getOrDefault("title", "").trim();
|
String title = body.getOrDefault("title", "").trim();
|
||||||
if (title.isEmpty() || title.length() > 100) {
|
if (title.isEmpty() || title.length() > 100) {
|
||||||
@ -135,7 +135,7 @@ public class ConversationController {
|
|||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权操作该会话");
|
return R.fail(403, "无权操作该会话");
|
||||||
}
|
}
|
||||||
conversationService.setPinned(conversationId, Boolean.TRUE.equals(body.get("pinned")));
|
conversationService.setPinned(conversationId, Boolean.TRUE.equals(body.get("pinned")));
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@ -174,7 +174,7 @@ public class ConversationController {
|
|||||||
public R<Void> clearMessages(@PathVariable String conversationId, Authentication auth) {
|
public R<Void> clearMessages(@PathVariable String conversationId, Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权操作该会话");
|
return R.fail(403, "无权操作该会话");
|
||||||
}
|
}
|
||||||
conversationService.clearMessages(conversationId);
|
conversationService.clearMessages(conversationId);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@ -188,8 +188,14 @@ public class ConversationController {
|
|||||||
@GetMapping("/{conversationId}/status")
|
@GetMapping("/{conversationId}/status")
|
||||||
public R<Map<String, String>> getStreamStatus(@PathVariable String conversationId, Authentication auth) {
|
public R<Map<String, String>> getStreamStatus(@PathVariable String conversationId, Authentication auth) {
|
||||||
String username = auth != null ? auth.getName() : "anonymous";
|
String username = auth != null ? auth.getName() : "anonymous";
|
||||||
|
// A freshly opened chat uses a client-generated id that is not persisted
|
||||||
|
// until the first message lands. The console polls this endpoint on an
|
||||||
|
// interval, so report idle for an unknown conversation instead of failing.
|
||||||
|
if (!conversationService.conversationExists(conversationId)) {
|
||||||
|
return R.ok(Map.of("streamStatus", "idle"));
|
||||||
|
}
|
||||||
if (!conversationService.isConversationOwner(conversationId, username)) {
|
if (!conversationService.isConversationOwner(conversationId, username)) {
|
||||||
return R.fail("无权访问该会话");
|
return R.fail(403, "无权访问该会话");
|
||||||
}
|
}
|
||||||
if (streamTracker.isRunning(conversationId)) {
|
if (streamTracker.isRunning(conversationId)) {
|
||||||
return R.ok(Map.of("streamStatus", "running"));
|
return R.ok(Map.of("streamStatus", "running"));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user