Skip to content

Commit

Permalink
Fix record import via some CSV files
Browse files Browse the repository at this point in the history
Some CSV files failed to detect as text/csv so the import failed.
ref: gabriel-vasile/mimetype#138
  • Loading branch information
tjerman authored and darh committed Jan 25, 2021
1 parent 01a7aa6 commit e32db50
Show file tree
Hide file tree
Showing 36 changed files with 1,469 additions and 575 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/Masterminds/squirrel v1.1.1-0.20191017225151-12f2162c8d8d
github.com/PaesslerAG/gval v1.0.1 // indirect
github.com/PaesslerAG/gval v1.0.1
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d
github.com/codegangsta/envy v0.0.0-20141216192214-4b78388c8ce4 // indirect
Expand All @@ -24,7 +24,7 @@ require (
github.com/disintegration/imaging v1.6.0
github.com/edwvee/exiffix v0.0.0-20180602190213-b57537c92a6b
github.com/fsnotify/fsnotify v1.4.9
github.com/gabriel-vasile/mimetype v0.3.17
github.com/gabriel-vasile/mimetype v1.1.2
github.com/getsentry/sentry-go v0.1.1
github.com/go-chi/chi v3.3.4+incompatible
github.com/go-chi/cors v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gabriel-vasile/mimetype v0.3.17 h1:NGWgggJJqTofUcTV1E7hkk2zVjZ54EfJa1z5O3z6By4=
github.com/gabriel-vasile/mimetype v0.3.17/go.mod h1:kMJbg3SlWZCsj4R73F1WDzbT9AyGCOVmUtIxxwO5pmI=
github.com/gabriel-vasile/mimetype v1.1.2 h1:gaPnPcNor5aZSVCJVSGipcpbgMWiAAj9z182ocSGbHU=
github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
github.com/getsentry/sentry-go v0.1.1 h1:5jcHHCJ+EUK+X8aoDbJUzZU1kG4ZFk2xX15BKv29v10=
github.com/getsentry/sentry-go v0.1.1/go.mod h1:2QfSdvxz4IZGyB5izm1TtADFhlhfj1Dcesrg8+A/T9Y=
github.com/go-chi/chi v3.3.4+incompatible h1:X+OApYAmoQS6jr1WoUgW+t5Ry5RYGXq2A//WAL5xdAU=
Expand Down
8 changes: 6 additions & 2 deletions pkg/envoy/csv/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ func Decoder() *decoder {

// CanDecodeFile determines if the file can be determined by this decoder
func (y *decoder) CanDecodeFile(f io.Reader) bool {
_, ext, err := mimetype.DetectReader(f)
m, err := mimetype.DetectReader(f)
if err != nil {
return false
}

return y.CanDecodeExt(ext)
return y.CanDecodeExt(m.Extension())
}

func (y *decoder) CanDecodeMime(m string) bool {
return m == "text/csv"
}

func (y *decoder) CanDecodeMime(m string) bool {
Expand Down
14 changes: 3 additions & 11 deletions pkg/envoy/json/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/cortezaproject/corteza-server/pkg/envoy"
"github.com/cortezaproject/corteza-server/pkg/envoy/resource"
"github.com/cortezaproject/corteza-server/pkg/mime"
"github.com/gabriel-vasile/mimetype"
)

Expand Down Expand Up @@ -39,26 +38,19 @@ func (d *decoder) CanDecodeFile(f io.Reader) bool {
var buff bytes.Buffer
tr := io.TeeReader(f, &buff)

_, ext, err := mimetype.DetectReader(tr)
m, err := mimetype.DetectReader(tr)
if err != nil {
return false
}

if ext == "txt" {
if is, err := mime.JsonL(&buff); err != nil {
return false
} else if is {
ext = "jsonl"
}
}
ext := m.Extension()

return d.CanDecodeExt(ext)
}

func (d *decoder) CanDecodeExt(ext string) bool {
pt := strings.Split(ext, ".")
ext = strings.TrimSpace(pt[len(pt)-1])
return ext == "jsonl" || ext == "json"
return ext == "jsonl" || ext == "json" || ext == "ndjson"
}

// Decode decodes the given io.Reader into a generic resource dataset
Expand Down
21 changes: 0 additions & 21 deletions pkg/mime/mime.go

This file was deleted.

6 changes: 3 additions & 3 deletions vendor/github.com/gabriel-vasile/mimetype/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/gabriel-vasile/mimetype/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions vendor/github.com/gabriel-vasile/mimetype/EXAMPLES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/gabriel-vasile/mimetype/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 40 additions & 21 deletions vendor/github.com/gabriel-vasile/mimetype/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/gabriel-vasile/mimetype/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e32db50

Please sign in to comment.