Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fileName to Handler readerConfig #3651

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ var (
ErrProcessingWarning = errors.New("error processing file")
)

type readerConfig struct{ fileExtension string }
type readerConfig struct {
fileName string
fileExtension string
}

type readerOption func(*readerConfig)

func withFileExtension(ext string) readerOption {
return func(c *readerConfig) { c.fileExtension = ext }
func withFileName(name string) readerOption {
return func(c *readerConfig) {
c.fileName = name
c.fileExtension = filepath.Ext(c.fileName)
}
}

// mimeTypeReader wraps an io.Reader with MIME type information.
Expand Down Expand Up @@ -358,7 +364,7 @@ func HandleFile(
return errors.New("reader is nil")
}

readerOption := withFileExtension(getFileExtension(chunkSkel))
readerOption := withFileName(getFileName(chunkSkel))
rdr, err := newFileReader(reader, readerOption)
if err != nil {
if errors.Is(err, ErrEmptyReader) {
Expand Down Expand Up @@ -456,11 +462,11 @@ func isFatal(err error) bool {
}
}

// getFileExtension extracts the file extension from the chunk's SourceMetadata.
// getFileName extracts the file name from the chunk's SourceMetadata.
// It considers all sources defined in the MetaData message.
// Note: Probably should add this as a method to the source_metadatapb object.
// then it'd just be chunkSkel.SourceMetadata.GetFileExtension()
func getFileExtension(chunkSkel *sources.Chunk) string {
// then it'd just be chunkSkel.SourceMetadata.GetFileName()
func getFileName(chunkSkel *sources.Chunk) string {
if chunkSkel == nil || chunkSkel.SourceMetadata == nil {
return ""
}
Expand Down Expand Up @@ -529,9 +535,7 @@ func getFileExtension(chunkSkel *sources.Chunk) string {
return ""
}

// Use filepath.Ext to extract the file extension from the file name
ext := filepath.Ext(fileName)
return ext
return fileName
}

// shouldHandleAsAPK checks if the file should be handled as an APK based on config and MIME type.
Expand Down
Loading