fix: Enhance Kol Variable Rendering and Management
- Updated the regex for placeholder matching to support more flexible key formats. - Refactored variable storage to allow both ID and key lookups in rendering. - Improved schema validation to check for duplicate keys and enforce non-empty keys. - Added new utility functions for variable value lookup and display name generation. - Enhanced tests to cover new key-based variable scenarios. - Refactored KolPrompt repository to simplify prompt storage and management, including the removal of obsolete revision handling. - Introduced new API endpoints for saving, activating, and archiving prompts. - Added new utility functions for handling Kol placeholders and platform options in the admin web. - Implemented database migrations to simplify prompt storage structure and ensure data integrity.
This commit is contained in:
@@ -277,25 +277,24 @@ func (h *KolManageHandler) DeletePrompt(c *gin.Context) {
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *KolManageHandler) SaveDraft(c *gin.Context) {
|
||||
func (h *KolManageHandler) SavePrompt(c *gin.Context) {
|
||||
promptID, ok := parseInt64Param(c, "id", "prompt id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
var req app.SaveDraftInput
|
||||
var req app.PublishPromptInput
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
req.PromptID = promptID
|
||||
|
||||
actor, ok := actorFromRequest(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.promptSvc.SaveDraft(c.Request.Context(), actor, req)
|
||||
data, err := h.promptSvc.Save(c.Request.Context(), actor, promptID, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
@@ -310,17 +309,64 @@ func (h *KolManageHandler) PublishPrompt(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var req app.PublishPromptInput
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
actor, ok := actorFromRequest(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.promptSvc.Publish(c.Request.Context(), actor, promptID); err != nil {
|
||||
data, err := h.promptSvc.Publish(c.Request.Context(), actor, promptID, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{"ok": true})
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *KolManageHandler) ActivatePrompt(c *gin.Context) {
|
||||
promptID, ok := parseInt64Param(c, "id", "prompt id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
actor, ok := actorFromRequest(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.promptSvc.Activate(c.Request.Context(), actor, promptID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *KolManageHandler) ArchivePrompt(c *gin.Context) {
|
||||
promptID, ok := parseInt64Param(c, "id", "prompt id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
actor, ok := actorFromRequest(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.promptSvc.Archive(c.Request.Context(), actor, promptID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *KolManageHandler) AssistSubmit(c *gin.Context) {
|
||||
|
||||
@@ -70,8 +70,10 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
kolManage.GET("/prompts/:id", kolManageHandler.GetPromptLatest)
|
||||
kolManage.PUT("/prompts/:id", kolManageHandler.UpdatePromptMetadata)
|
||||
kolManage.DELETE("/prompts/:id", kolManageHandler.DeletePrompt)
|
||||
kolManage.POST("/prompts/:id/draft", kolManageHandler.SaveDraft)
|
||||
kolManage.POST("/prompts/:id/save", kolManageHandler.SavePrompt)
|
||||
kolManage.POST("/prompts/:id/publish", kolManageHandler.PublishPrompt)
|
||||
kolManage.PUT("/prompts/:id/activate", kolManageHandler.ActivatePrompt)
|
||||
kolManage.PUT("/prompts/:id/archive", kolManageHandler.ArchivePrompt)
|
||||
kolManage.POST("/assist", kolManageHandler.AssistSubmit)
|
||||
kolManage.GET("/assist/:id", kolManageHandler.AssistGet)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user