Enhance asset upload management in neo package

- Added support for custom asset upload settings in the Upload struct, allowing for more flexible file handling.
- Implemented logic in initUpload to register default or custom asset upload configurations based on user settings.
- Improved error handling during asset registration to ensure robust functionality.
This commit is contained in:
Max 2025-05-31 13:33:23 +08:00
parent a9b6eed025
commit 43686be6e4
3 changed files with 18 additions and 1 deletions

View file

@ -41,7 +41,7 @@ func RegisterDefault(name string) (*Manager, error) {
option := ManagerOption{
Driver: "local",
Options: map[string]interface{}{"path": filepath.Join(config.Conf.DataRoot, "attachments")},
Options: map[string]interface{}{"path": filepath.Join(config.Conf.DataRoot, name)},
MaxSize: "50M",
ChunkSize: "2M",
AllowedTypes: []string{

View file

@ -148,6 +148,22 @@ func initUpload() error {
}
}
// Use the chat upload setting for asset upload, if the asset upload setting is not set. (public assets)
if Neo.UploadSetting.Assets == nil {
_, err := attachment.RegisterDefault("assets")
if err != nil {
return err
}
}
// Use custom asset upload setting
if Neo.UploadSetting.Assets != nil {
Neo.UploadSetting.Assets.ReplaceEnv(config.Conf.DataRoot)
_, err := attachment.Register("assets", Neo.UploadSetting.Assets.Driver, *Neo.UploadSetting.Assets)
if err != nil {
return err
}
}
return nil
}

View file

@ -82,6 +82,7 @@ type AuthFields struct {
// ===============================
type Upload struct {
Chat *attachment.ManagerOption `json:"chat,omitempty" yaml:"chat,omitempty"` // Chat conversation upload setting, if not set use the local and root path is `/attachments`.
Assets *attachment.ManagerOption `json:"assets,omitempty" yaml:"assets,omitempty"` // Asset upload setting, if not set use the chat upload setting.
Knowledge *attachment.ManagerOption `json:"knowledge,omitempty" yaml:"knowledge,omitempty"` // Knowledge base upload setting, if not set use the chat upload setting.
}