yao/neo/neo.go
Max 445bcdd7ea Implement file download functionality and refactor existing methods in neo package
- Added handleDownload method to manage file download requests, including validation for session ID and file ID.
- Enhanced permission checks to ensure users can only download files they are authorized to access.
- Updated CORS headers to include Content-Disposition for better file handling in responses.
- Removed deprecated download logic from the neo package to streamline code and improve maintainability.
- Refactored existing methods to improve clarity and error handling during file operations.
2025-06-01 18:33:38 +08:00

61 lines
1.6 KiB
Go

package neo
import (
"github.com/gin-gonic/gin"
"github.com/yaoapp/gou/session"
"github.com/yaoapp/yao/neo/assistant"
chatctx "github.com/yaoapp/yao/neo/context"
)
// Answer reply the message
func (neo *DSL) Answer(ctx chatctx.Context, question string, c *gin.Context) error {
var err error
var ast assistant.API = Neo.Assistant
if ctx.AssistantID != "" {
ast, err = neo.Select(ctx.AssistantID)
if err != nil {
return err
}
}
_, err = ast.Execute(c, ctx, question, nil)
return err
}
// Select select an assistant
func (neo *DSL) Select(id string) (assistant.API, error) {
if id == "" {
return Neo.Assistant, nil
}
return assistant.Get(id)
}
// UserID get the user id from the session
func (neo *DSL) UserID(sid string) (interface{}, error) {
fieldID := neo.AuthSetting.SessionFields.ID
return session.Global().ID(sid).Get(fieldID)
}
// GuestID get the guest id from the session
func (neo *DSL) GuestID(sid string) (interface{}, error) {
fieldGuest := neo.AuthSetting.SessionFields.Guest
return session.Global().ID(sid).Get(fieldGuest)
}
// UserRoles get the user roles from the session
func (neo *DSL) UserRoles(sid string) (interface{}, error) {
fieldRoles := neo.AuthSetting.SessionFields.Roles
return session.Global().ID(sid).Get(fieldRoles)
}
// UserOrGuestID get the user id or guest id from the session
func (neo *DSL) UserOrGuestID(sid string) (interface{}, bool, error) {
userID, err := neo.UserID(sid)
if err != nil {
guestID, err := neo.GuestID(sid)
if err != nil {
return nil, false, err
}
return guestID, true, nil
}
return userID, false, nil
}