Skip to content

Commit

Permalink
use mimeutils
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf committed Apr 25, 2024
1 parent 782943c commit a8aa938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 4 additions & 11 deletions pkg/contexts/ocm/accessmethods/mvn/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/open-component-model/ocm/pkg/mime"
"github.com/open-component-model/ocm/pkg/mimeutils"
)

// Artifact holds the typical Maven coordinates groupId, artifactId, version and packaging.
Expand Down Expand Up @@ -86,17 +87,9 @@ func (a *Artifact) ClassifierExtensionFrom(filename string) *Artifact {
// MimeType returns the MIME type of the Maven Artifact based on the file extension.
// Default is application/x-tgz.
func (a *Artifact) MimeType() string {
switch a.Extension {
case "jar":
return mime.MIME_JAR
case "json", "module":
return mime.MIME_JSON
case "pom", "xml":
return mime.MIME_XML
case "tar.gz":
return mime.MIME_TGZ
case "zip":
return mime.MIME_GZIP
m := mimeutils.TypeByExtension("." + a.Extension)
if m != "" {
return m
}
return mime.MIME_TGZ
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/mimeutils/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ var builtinTypesLower = map[string]string{
".webp": "image/webp",
".xml": "text/xml; charset=utf-8",
// added entries
".txt": ocmmime.MIME_TEXT,
".yaml": ocmmime.MIME_YAML_OFFICIAL,
".gzip": ocmmime.MIME_GZIP,
".tar": ocmmime.MIME_TAR,
".tgz": ocmmime.MIME_TGZ,
".txt": ocmmime.MIME_TEXT,
".yaml": ocmmime.MIME_YAML_OFFICIAL,
".gzip": ocmmime.MIME_GZIP,
".tar": ocmmime.MIME_TAR,
".tgz": ocmmime.MIME_TGZ,
".tar.gz": ocmmime.MIME_TGZ,
".pom": ocmmime.MIME_XML,
".zip": ocmmime.MIME_GZIP,
".jar": ocmmime.MIME_JAR,
".module": ocmmime.MIME_JSON, // gradle module metadata
}

var once sync.Once // guards initMime
Expand Down

0 comments on commit a8aa938

Please sign in to comment.