🎨 优化角色卡功能模块,后续待优化图像上传&前端流畅性待优化
This commit is contained in:
@@ -1,34 +1,40 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.echol.cn/loser/st/server/model/app"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CharacterResponse 角色卡响应
|
||||
type CharacterResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Personality string `json:"personality"`
|
||||
Scenario string `json:"scenario"`
|
||||
Avatar string `json:"avatar"`
|
||||
CreatorID *uint `json:"creatorId"`
|
||||
CreatorName string `json:"creatorName"`
|
||||
CreatorNotes string `json:"creatorNotes"`
|
||||
Tags []string `json:"tags"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Version int `json:"version"`
|
||||
FirstMessage string `json:"firstMessage"`
|
||||
ExampleMessages []string `json:"exampleMessages"`
|
||||
TotalChats int `json:"totalChats"`
|
||||
TotalLikes int `json:"totalLikes"`
|
||||
UsageCount int `json:"usageCount"`
|
||||
FavoriteCount int `json:"favoriteCount"`
|
||||
TokenCount int `json:"tokenCount"`
|
||||
IsFavorited bool `json:"isFavorited"` // 当前用户是否收藏
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Personality string `json:"personality"`
|
||||
Scenario string `json:"scenario"`
|
||||
Avatar string `json:"avatar"`
|
||||
CreatorID *uint `json:"creatorId"`
|
||||
CreatorName string `json:"creatorName"`
|
||||
CreatorNotes string `json:"creatorNotes"`
|
||||
Tags []string `json:"tags"`
|
||||
IsPublic bool `json:"isPublic"`
|
||||
Version int `json:"version"`
|
||||
FirstMessage string `json:"firstMessage"`
|
||||
ExampleMessages []string `json:"exampleMessages"`
|
||||
SystemPrompt string `json:"systemPrompt"`
|
||||
PostHistoryInstructions string `json:"postHistoryInstructions"`
|
||||
AlternateGreetings []string `json:"alternateGreetings"`
|
||||
CharacterBook json.RawMessage `json:"characterBook"`
|
||||
Extensions json.RawMessage `json:"extensions"`
|
||||
TotalChats int `json:"totalChats"`
|
||||
TotalLikes int `json:"totalLikes"`
|
||||
UsageCount int `json:"usageCount"`
|
||||
FavoriteCount int `json:"favoriteCount"`
|
||||
TokenCount int `json:"tokenCount"`
|
||||
IsFavorited bool `json:"isFavorited"` // 当前用户是否收藏
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// CharacterListResponse 角色卡列表响应
|
||||
@@ -52,28 +58,49 @@ func ToCharacterResponse(character *app.AICharacter, isFavorited bool) Character
|
||||
exampleMessages = character.ExampleMessages
|
||||
}
|
||||
|
||||
alternateGreetings := []string{}
|
||||
if character.AlternateGreetings != nil {
|
||||
alternateGreetings = character.AlternateGreetings
|
||||
}
|
||||
|
||||
// 处理 JSON 字段,确保返回有效 JSON(nil 时返回 null)
|
||||
characterBook := json.RawMessage(character.CharacterBook)
|
||||
if len(characterBook) == 0 {
|
||||
characterBook = json.RawMessage("null")
|
||||
}
|
||||
|
||||
extensions := json.RawMessage(character.Extensions)
|
||||
if len(extensions) == 0 {
|
||||
extensions = json.RawMessage("null")
|
||||
}
|
||||
|
||||
return CharacterResponse{
|
||||
ID: character.ID,
|
||||
Name: character.Name,
|
||||
Description: character.Description,
|
||||
Personality: character.Personality,
|
||||
Scenario: character.Scenario,
|
||||
Avatar: character.Avatar,
|
||||
CreatorID: character.CreatorID,
|
||||
CreatorName: character.CreatorName,
|
||||
CreatorNotes: character.CreatorNotes,
|
||||
Tags: tags,
|
||||
IsPublic: character.IsPublic,
|
||||
Version: character.Version,
|
||||
FirstMessage: character.FirstMessage,
|
||||
ExampleMessages: exampleMessages,
|
||||
TotalChats: character.TotalChats,
|
||||
TotalLikes: character.TotalLikes,
|
||||
UsageCount: character.UsageCount,
|
||||
FavoriteCount: character.FavoriteCount,
|
||||
TokenCount: character.TokenCount,
|
||||
IsFavorited: isFavorited,
|
||||
CreatedAt: character.CreatedAt,
|
||||
UpdatedAt: character.UpdatedAt,
|
||||
ID: character.ID,
|
||||
Name: character.Name,
|
||||
Description: character.Description,
|
||||
Personality: character.Personality,
|
||||
Scenario: character.Scenario,
|
||||
Avatar: character.Avatar,
|
||||
CreatorID: character.CreatorID,
|
||||
CreatorName: character.CreatorName,
|
||||
CreatorNotes: character.CreatorNotes,
|
||||
Tags: tags,
|
||||
IsPublic: character.IsPublic,
|
||||
Version: character.Version,
|
||||
FirstMessage: character.FirstMessage,
|
||||
ExampleMessages: exampleMessages,
|
||||
SystemPrompt: character.SystemPrompt,
|
||||
PostHistoryInstructions: character.PostHistoryInstructions,
|
||||
AlternateGreetings: alternateGreetings,
|
||||
CharacterBook: characterBook,
|
||||
Extensions: extensions,
|
||||
TotalChats: character.TotalChats,
|
||||
TotalLikes: character.TotalLikes,
|
||||
UsageCount: character.UsageCount,
|
||||
FavoriteCount: character.FavoriteCount,
|
||||
TokenCount: character.TokenCount,
|
||||
IsFavorited: isFavorited,
|
||||
CreatedAt: character.CreatedAt,
|
||||
UpdatedAt: character.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user