fix: 优化后端各模块 handler
- database_handler, knowledge_handler, model_handler - neo4j_handler, sub_table_handler - system_handler, upload_handler - knowledge_service, upload_service Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -155,9 +155,9 @@ func (s *KnowledgeService) Delete(id string) error {
|
||||
|
||||
// 删除每个文档的 MinIO 文件和本地 Markdown 文件
|
||||
for _, doc := range docs {
|
||||
// 删除 MinIO 文件
|
||||
if doc.FileKey != "" && kb.StorageConfig.Type == "minio" {
|
||||
s.uploadService.DeleteFileWithConfig(doc.FileKey, kb.StorageConfig)
|
||||
// 删除存储文件(MinIO 或本地)
|
||||
if doc.FileKey != "" {
|
||||
s.uploadService.DeleteFileWithConfig(doc.FileKey, kb.StorageConfig, kb.Name)
|
||||
}
|
||||
// 删除本地 Markdown 文件
|
||||
if s.markdownLocalPath != "" {
|
||||
@@ -215,15 +215,15 @@ func (s *KnowledgeService) UploadDocument(kbID string, file *multipart.FileHeade
|
||||
|
||||
// 上传文件(根据知识库的 storage_config 选择存储方式)
|
||||
var result *UploadResponse
|
||||
if kb.StorageConfig.Type != "" {
|
||||
// 使用知识库的存储配置
|
||||
if kb.StorageConfig.Type != "" && kb.StorageConfig.Type != "local" {
|
||||
// 使用知识库的存储配置(MinIO)
|
||||
knowledgeDebugLog.Printf("[Knowledge Upload] 使用知识库存储配置: type=%s, endpoint=%s, bucket=%s",
|
||||
kb.StorageConfig.Type, kb.StorageConfig.Endpoint, kb.StorageConfig.Bucket)
|
||||
result, err = s.uploadService.UploadWithConfig(file, kb.StorageConfig)
|
||||
} else {
|
||||
// 使用全局配置
|
||||
knowledgeDebugLog.Printf("[Knowledge Upload] 使用全局存储配置")
|
||||
result, err = s.uploadService.Upload(file)
|
||||
// 本地存储,使用知识库名称作为子目录
|
||||
knowledgeDebugLog.Printf("[Knowledge Upload] 使用本地存储,路径: resources/%s/", kb.Name)
|
||||
result, err = s.uploadService.UploadToKnowledgeBase(file, kb.StorageConfig, kb.Name)
|
||||
}
|
||||
if err != nil {
|
||||
knowledgeDebugLog.Printf("[Knowledge Upload] 错误: 上传失败, err=%v", err)
|
||||
@@ -419,13 +419,8 @@ func (s *KnowledgeService) DeleteDocument(kbID, docID string) error {
|
||||
if doc.FileKey != "" {
|
||||
knowledgeDebugLog.Printf("[Knowledge DeleteDocument] 删除文件: kbID=%s, docID=%s, fileKey=%s, storageType=%s",
|
||||
kbID, docID, doc.FileKey, kb.StorageConfig.Type)
|
||||
if kb.StorageConfig.Type != "" {
|
||||
// 使用知识库的存储配置删除
|
||||
s.uploadService.DeleteFileWithConfig(doc.FileKey, kb.StorageConfig)
|
||||
} else {
|
||||
// 使用全局配置删除
|
||||
s.uploadService.DeleteFile(doc.FileKey)
|
||||
}
|
||||
// 使用知识库的存储配置删除(传入知识库名称)
|
||||
s.uploadService.DeleteFileWithConfig(doc.FileKey, kb.StorageConfig, kb.Name)
|
||||
}
|
||||
|
||||
// 删除文档记录
|
||||
|
||||
Reference in New Issue
Block a user