Merged in feature/doc_import (pull request #177)

integration of background processor

* integration part 1

* feature working

* fix mimetype issue
This commit is contained in:
Jay Brown
2025-08-20 19:01:13 +00:00
parent 7a693d42f5
commit 720a84be92
34 changed files with 2682 additions and 193 deletions
+23 -3
View File
@@ -3,6 +3,8 @@ package documentupload
import (
"context"
"io"
"mime"
"path/filepath"
"time"
"queryorchestration/internal/database/repository"
@@ -16,6 +18,19 @@ import (
type File struct {
ClientID string
Content io.Reader
BatchID *uuid.UUID // Optional batch ID for batch processing
Filename string // Original filename for MIME type detection
}
// detectContentType determines the MIME type based on file extension
func detectContentType(filename string) string {
// Use Go's standard library to detect MIME type from extension
contentType := mime.TypeByExtension(filepath.Ext(filename))
if contentType == "" {
// Default to binary if extension is unknown
return "application/octet-stream"
}
return contentType
}
func (s *Service) Upload(ctx context.Context, file File) error {
@@ -40,6 +55,7 @@ func (s *Service) Upload(ctx context.Context, file File) error {
CreatedAt: now,
EntityID: uploadId,
Part: &newPart,
BatchID: file.BatchID,
}
keyStr := key.String()
bucket := s.cfg.GetBucket()
@@ -59,10 +75,14 @@ func (s *Service) Upload(ctx context.Context, file File) error {
return err
}
// Detect content type from original filename
contentType := detectContentType(file.Filename)
_, err = s.cfg.GetStoreClient().PutObject(ctx, &s3.PutObjectInput{
Bucket: &bucket,
Key: &keyStr,
Body: file.Content,
Bucket: &bucket,
Key: &keyStr,
Body: file.Content,
ContentType: &contentType,
})
if err != nil {
return err
+1
View File
@@ -43,6 +43,7 @@ func TestUpload(t *testing.T) {
file := documentupload.File{
ClientID: "client_id",
Content: strings.NewReader("abc"),
Filename: "test.txt",
}
log.Print("test")