messageApi.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // dashboard-v4/dashboard/src/services/messageApi.ts
  2. import type {
  3. CreateMessageRequest,
  4. MessageListResponse,
  5. ApiResponse,
  6. MessageNode,
  7. } from "../types/chat";
  8. export const messageApi = {
  9. async getMessages(chatId: string): Promise<ApiResponse<MessageListResponse>> {
  10. const response = await fetch(`/api/v2/chat-messages?chat=${chatId}`);
  11. return response.json();
  12. },
  13. async createMessages(
  14. chatId: string,
  15. request: CreateMessageRequest
  16. ): Promise<ApiResponse<MessageNode[]>> {
  17. const response = await fetch("/api/v2/chat-messages", {
  18. method: "POST",
  19. headers: { "Content-Type": "application/json" },
  20. body: JSON.stringify({
  21. chat_id: chatId,
  22. ...request,
  23. }),
  24. });
  25. return response.json();
  26. },
  27. async switchVersion(
  28. chatId: string,
  29. messageUids: string[]
  30. ): Promise<ApiResponse<void>> {
  31. const response = await fetch("/api/v2/chat-messages/switch-version", {
  32. method: "POST",
  33. headers: { "Content-Type": "application/json" },
  34. body: JSON.stringify({
  35. chat_id: chatId,
  36. message_uids: messageUids,
  37. }),
  38. });
  39. return response.json();
  40. },
  41. async likeMessage(messageId: string): Promise<ApiResponse<void>> {
  42. const response = await fetch(`/api/v2/chat-messages/${messageId}/like`, {
  43. method: "POST",
  44. });
  45. return response.json();
  46. },
  47. async dislikeMessage(messageId: string): Promise<ApiResponse<void>> {
  48. const response = await fetch(`/api/v2/chat-messages/${messageId}/dislike`, {
  49. method: "POST",
  50. });
  51. return response.json();
  52. },
  53. async shareMessage(
  54. messageId: string
  55. ): Promise<ApiResponse<{ shareUrl: string }>> {
  56. const response = await fetch(`/api/v2/chat-messages/${messageId}/share`, {
  57. method: "POST",
  58. });
  59. return response.json();
  60. },
  61. async deleteMessage(messageId: string): Promise<ApiResponse<void>> {
  62. const response = await fetch(`/api/v2/chat-messages/${messageId}`, {
  63. method: "DELETE",
  64. });
  65. return response.json();
  66. },
  67. };