3
0

Add content type assertion fallback for JSON file imports

This commit is contained in:
Tomaž Jerman
2022-05-23 13:47:20 +02:00
committed by Denis Arh
parent c1412615b9
commit 5d8f00df64
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ func (svc *importSession) Create(ctx context.Context, f io.ReadSeeker, name, con
}
f.Seek(0, 0)
if jd.CanDecodeFile(f) {
if jd.CanDecodeFile(f) || jd.CanDecodeMime(contentType) {
f.Seek(0, 0)
return jd.Decode(ctx, f, do)
}
+4
View File
@@ -48,6 +48,10 @@ func (d *decoder) CanDecodeFile(f io.Reader) bool {
return d.CanDecodeExt(ext)
}
func (d *decoder) CanDecodeMime(m string) bool {
return m == "application/json" || m == "application/jsonlines"
}
func (d *decoder) CanDecodeExt(ext string) bool {
pt := strings.Split(ext, ".")
ext = strings.TrimSpace(pt[len(pt)-1])