Files
wehub-resource-sync f36e2104d8
tests / ragflow_tests_infinity (push) Has been cancelled
tests / ragflow_tests_elasticsearch (push) Has been cancelled
sep-tests / ragflow_preflight (push) Has been cancelled
sep-tests / ragflow_tests_infinity (push) Has been cancelled
sep-tests / ragflow_tests_elasticsearch (push) Has been cancelled
tests / ragflow_preflight (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:16:49 +08:00

43 lines
975 B
Go

package service
import (
"encoding/hex"
"path/filepath"
"regexp"
"strings"
"ragflow/internal/utility"
"github.com/zeebo/xxh3"
)
var (
presentationUploadPattern = regexp.MustCompile(`(?i)\.(ppt|pptx|pages)$`)
emailUploadPattern = regexp.MustCompile(`(?i)\.(msg|eml)$`)
)
// selectUploadParser mirrors Python FileService.get_parser.
func selectUploadParser(docType utility.FileType, filename, defaultParser string) string {
switch docType {
case utility.FileTypeVISUAL:
return "picture"
case utility.FileTypeAURAL:
return "audio"
}
base := filepath.Base(strings.TrimSpace(filename))
switch {
case presentationUploadPattern.MatchString(base):
return "presentation"
case emailUploadPattern.MatchString(base):
return "email"
default:
return defaultParser
}
}
// contentHashHex mirrors Python xxhash.xxh128(blob).hexdigest().
func contentHashHex(blob []byte) string {
sum := xxh3.Hash128(blob).Bytes()
return hex.EncodeToString(sum[:])
}