新增正则和扩展模块

This commit is contained in:
2026-02-11 23:44:09 +08:00
parent 2bca8e2788
commit 4e611d3a5e
47 changed files with 10058 additions and 49 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"git.echol.cn/loser/st/server/global"
"git.echol.cn/loser/st/server/middleware"
@@ -61,7 +62,15 @@ func (a *WorldInfoApi) CreateWorldBook(c *gin.Context) {
// @Router /app/worldbook/:id [put]
func (a *WorldInfoApi) UpdateWorldBook(c *gin.Context) {
userID := middleware.GetAppUserID(c)
bookID := c.GetUint("id")
// 从路径参数获取 ID
idStr := c.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的世界书ID", c)
return
}
bookID := uint(id)
var req request.UpdateWorldBookRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -89,7 +98,15 @@ func (a *WorldInfoApi) UpdateWorldBook(c *gin.Context) {
// @Router /app/worldbook/:id [delete]
func (a *WorldInfoApi) DeleteWorldBook(c *gin.Context) {
userID := middleware.GetAppUserID(c)
bookID := c.GetUint("id")
// 从路径参数获取 ID
idStr := c.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的世界书ID", c)
return
}
bookID := uint(id)
if err := worldInfoService.DeleteWorldBook(userID, bookID); err != nil {
global.GVA_LOG.Error("删除世界书失败", zap.Error(err))
@@ -111,7 +128,15 @@ func (a *WorldInfoApi) DeleteWorldBook(c *gin.Context) {
// @Router /app/worldbook/:id [get]
func (a *WorldInfoApi) GetWorldBook(c *gin.Context) {
userID := middleware.GetAppUserID(c)
bookID := c.GetUint("id")
// 从路径参数获取 ID
idStr := c.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的世界书ID", c)
return
}
bookID := uint(id)
book, err := worldInfoService.GetWorldBook(userID, bookID)
if err != nil {
@@ -334,7 +359,15 @@ func (a *WorldInfoApi) ImportWorldBook(c *gin.Context) {
// @Router /app/worldbook/:id/export [get]
func (a *WorldInfoApi) ExportWorldBook(c *gin.Context) {
userID := middleware.GetAppUserID(c)
bookID := c.GetUint("id")
// 从路径参数获取 ID
idStr := c.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的世界书ID", c)
return
}
bookID := uint(id)
exportData, err := worldInfoService.ExportWorldBook(userID, bookID)
if err != nil {
@@ -399,10 +432,18 @@ func (a *WorldInfoApi) MatchWorldInfo(c *gin.Context) {
// @Router /app/worldbook/character/:characterId [get]
func (a *WorldInfoApi) GetCharacterWorldBooks(c *gin.Context) {
userID := middleware.GetAppUserID(c)
characterID := c.GetUint("characterId")
// 从路径参数获取 ID
idStr := c.Param("characterId")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的角色ID", c)
return
}
characterID := uint(id)
var books []app.AIWorldInfo
err := global.GVA_DB.
err = global.GVA_DB.
Where("user_id = ? AND (is_global = true OR ? = ANY(linked_chars))", userID, fmt.Sprintf("%d", characterID)).
Find(&books).Error
@@ -431,7 +472,15 @@ func (a *WorldInfoApi) GetCharacterWorldBooks(c *gin.Context) {
// @Router /app/worldbook/:id/duplicate [post]
func (a *WorldInfoApi) DuplicateWorldBook(c *gin.Context) {
userID := middleware.GetAppUserID(c)
bookID := c.GetUint("id")
// 从路径参数获取 ID
idStr := c.Param("id")
id, err := strconv.ParseUint(idStr, 10, 32)
if err != nil {
sysResponse.FailWithMessage("无效的世界书ID", c)
return
}
bookID := uint(id)
// 获取原世界书
book, err := worldInfoService.GetWorldBook(userID, bookID)