|
15 | 15 | package image |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "encoding/json" |
19 | 18 | "io" |
20 | 19 | "io/ioutil" |
21 | 20 | "net/http" |
@@ -67,46 +66,11 @@ func Autodetect(path string) (string, error) { |
67 | 66 | return TypeImage, nil |
68 | 67 |
|
69 | 68 | case "text/plain; charset=utf-8": |
70 | | - // might be a JSON file, will be handled below |
| 69 | + // might be a JSON file |
| 70 | + return schema.Autodect(f) |
71 | 71 |
|
72 | 72 | default: |
73 | 73 | return "", errors.New("unknown file type") |
74 | 74 | } |
75 | 75 |
|
76 | | - if _, err := f.Seek(0, os.SEEK_SET); err != nil { |
77 | | - return "", errors.Wrap(err, "unable to seek") |
78 | | - } |
79 | | - |
80 | | - header := struct { |
81 | | - SchemaVersion int `json:"schemaVersion"` |
82 | | - MediaType string `json:"mediaType"` |
83 | | - Config interface{} `json:"config"` |
84 | | - }{} |
85 | | - |
86 | | - if err := json.NewDecoder(f).Decode(&header); err != nil { |
87 | | - if _, errSeek := f.Seek(0, os.SEEK_SET); errSeek != nil { |
88 | | - return "", errors.Wrap(err, "unable to seek") |
89 | | - } |
90 | | - |
91 | | - e := errors.Wrap( |
92 | | - schema.WrapSyntaxError(f, err), |
93 | | - "unable to parse JSON", |
94 | | - ) |
95 | | - |
96 | | - return "", e |
97 | | - } |
98 | | - |
99 | | - switch { |
100 | | - case header.MediaType == string(schema.MediaTypeManifest): |
101 | | - return TypeManifest, nil |
102 | | - |
103 | | - case header.MediaType == string(schema.MediaTypeManifestList): |
104 | | - return TypeManifestList, nil |
105 | | - |
106 | | - case header.MediaType == "" && header.SchemaVersion == 0 && header.Config != nil: |
107 | | - // config files don't have mediaType/schemaVersion header |
108 | | - return TypeConfig, nil |
109 | | - } |
110 | | - |
111 | | - return "", errors.New("unknown media type") |
112 | 76 | } |
0 commit comments