fix:attachment_document_failed
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Tencent/WeKnora/internal/common"
|
||||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser"
|
"github.com/Tencent/WeKnora/internal/infrastructure/docparser"
|
||||||
"github.com/Tencent/WeKnora/internal/logger"
|
"github.com/Tencent/WeKnora/internal/logger"
|
||||||
"github.com/Tencent/WeKnora/internal/types"
|
"github.com/Tencent/WeKnora/internal/types"
|
||||||
@@ -117,6 +118,8 @@ func (p *AttachmentProcessor) ProcessAttachment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attachment.Content = common.CleanInvalidUTF8(attachment.Content)
|
||||||
|
|
||||||
logger.Infof(ctx, "attachment processed: fileName=%s, truncated=%v, contentLen=%d",
|
logger.Infof(ctx, "attachment processed: fileName=%s, truncated=%v, contentLen=%d",
|
||||||
secutils.SanitizeForLog(baseName), attachment.IsTruncated, len(attachment.Content))
|
secutils.SanitizeForLog(baseName), attachment.IsTruncated, len(attachment.Content))
|
||||||
|
|
||||||
@@ -232,11 +235,14 @@ func (p *AttachmentProcessor) processWithDocumentReader(
|
|||||||
if p.documentReader == nil {
|
if p.documentReader == nil {
|
||||||
return fmt.Errorf("DocumentReader not configured")
|
return fmt.Errorf("DocumentReader not configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizedType := strings.TrimPrefix(fileType, ".")
|
||||||
|
|
||||||
result, err := p.documentReader.Read(ctx, &types.ReadRequest{
|
result, err := p.documentReader.Read(ctx, &types.ReadRequest{
|
||||||
FileContent: data,
|
FileContent: data,
|
||||||
FileName: fileName,
|
FileName: fileName,
|
||||||
FileType: fileType,
|
FileType: normalizedType,
|
||||||
|
ParserEngineOverrides: getParserEngineOverridesFromContext(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("DocumentReader failed: %w", err)
|
return fmt.Errorf("DocumentReader failed: %w", err)
|
||||||
@@ -301,6 +307,16 @@ func isValidFileType(fileName string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getParserEngineOverridesFromContext returns parser engine overrides from tenant in context.
|
||||||
|
func getParserEngineOverridesFromContext(ctx context.Context) map[string]string {
|
||||||
|
if v := ctx.Value(types.TenantInfoContextKey); v != nil {
|
||||||
|
if tenant, ok := v.(*types.Tenant); ok && tenant != nil && tenant.ParserEngineConfig != nil {
|
||||||
|
return tenant.ParserEngineConfig.ToOverridesMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// DecodeBase64Attachment decodes a base64 attachment payload, stripping any data URI prefix.
|
// DecodeBase64Attachment decodes a base64 attachment payload, stripping any data URI prefix.
|
||||||
// Tries Std, URL, RawStd, and RawURL encodings in order.
|
// Tries Std, URL, RawStd, and RawURL encodings in order.
|
||||||
func DecodeBase64Attachment(data string) ([]byte, error) {
|
func DecodeBase64Attachment(data string) ([]byte, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user