81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
41 lines
883 B
Go
41 lines
883 B
Go
package documentclean
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
documenttypes "queryorchestration/internal/document/types"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
)
|
|
|
|
type Content interface {
|
|
IsCorrupt(context.Context) *documenttypes.InvalidDocumentReason
|
|
}
|
|
|
|
func (s *Service) getContent(ctx context.Context, params *CleanParams, mimeType documenttypes.MimeType) (Content, error) {
|
|
resp, err := s.cfg.GetStoreClient().GetObject(ctx, &s3.GetObjectInput{
|
|
Bucket: ¶ms.Location.Bucket,
|
|
Key: ¶ms.Location.Key,
|
|
IfMatch: ¶ms.Hash,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var content Content
|
|
switch mimeType {
|
|
case documenttypes.MimeTypePDF:
|
|
pdf, err := documenttypes.NewPDFFromReadCloser(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
content = pdf
|
|
default:
|
|
return nil, errors.New("invalid mimetype")
|
|
}
|
|
|
|
return content, nil
|
|
}
|