2025-04-22 14:40:16 +00:00
|
|
|
package documenttext
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"log/slog"
|
|
|
|
|
|
|
|
|
|
documenttypes "queryorchestration/internal/document/types"
|
|
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (s *Service) executeExtraction(ctx context.Context, documentId uuid.UUID) error {
|
|
|
|
|
clean, err := s.cfg.GetDBQueries().GetCleanEntryByDocId(ctx, documentId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
} else if clean.Fail.Valid {
|
|
|
|
|
slog.Error("document has no clean document", "id", documentId)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key, err := objectstore.ParseBucketKey(*clean.Key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doc, err := documenttypes.GetFile(ctx, s.cfg, documenttypes.GetFileParams{
|
|
|
|
|
Bucket: *clean.Bucket,
|
|
|
|
|
Key: key,
|
|
|
|
|
Hash: *clean.Hash,
|
|
|
|
|
Mimetype: documenttypes.ParseDBNullMimeType(clean.Mimetype),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 12:36:47 +00:00
|
|
|
text, err := s.GetDocumentText(ctx, doc)
|
2025-04-22 14:40:16 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = s.storeProcess(ctx, text, clean)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|