diff --git a/dist/main-amd64-darwin b/dist/main-amd64-darwin index 1e24a6c..bb5e439 100755 Binary files a/dist/main-amd64-darwin and b/dist/main-amd64-darwin differ diff --git a/dist/main-amd64-linux b/dist/main-amd64-linux index c773ff8..834fca6 100755 Binary files a/dist/main-amd64-linux and b/dist/main-amd64-linux differ diff --git a/dist/main-arm-linux b/dist/main-arm-linux index e2454ea..f4fa6be 100755 Binary files a/dist/main-arm-linux and b/dist/main-arm-linux differ diff --git a/dist/main-arm64-darwin b/dist/main-arm64-darwin index 0d608b5..563929e 100755 Binary files a/dist/main-arm64-darwin and b/dist/main-arm64-darwin differ diff --git a/dist/main-arm64-linux b/dist/main-arm64-linux index 83e3157..77fa997 100755 Binary files a/dist/main-arm64-linux and b/dist/main-arm64-linux differ diff --git a/dist/metadata.json b/dist/metadata.json index 30ef48e..3ebf558 100644 --- a/dist/metadata.json +++ b/dist/metadata.json @@ -1 +1 @@ -{"project_name":"az-storage-upload","tag":"v0.0.0","previous_tag":"","version":"v0.0.0","commit":"3b2da2b27988784403e5d88de02dc90adbd4801e","date":"2025-01-08T14:43:25.510055576Z","runtime":{"goos":"linux","goarch":"amd64"}} \ No newline at end of file +{"project_name":"az-storage-upload","tag":"v0.0.0","previous_tag":"","version":"v0.0.0","commit":"99dc272f23b892f94f78b1367598247b70b4f26e","date":"2025-01-08T15:31:56.147747269Z","runtime":{"goos":"linux","goarch":"amd64"}} \ No newline at end of file diff --git a/examples/demo/main.css b/examples/demo/main.css new file mode 100644 index 0000000..7a577a4 --- /dev/null +++ b/examples/demo/main.css @@ -0,0 +1,21 @@ +/* Applies to the entire body of the HTML document (except where overridden by more specific +selectors). */ +body { + margin: 25px; + background-color: rgb(240,240,240); + font-family: arial, sans-serif; + font-size: 14px; + } + + /* Applies to all

...

elements. */ + h1 { + font-size: 35px; + font-weight: normal; + margin-top: 5px; + } + + /* Applies to all elements with <... class="someclass"> specified. */ + .someclass { color: red; } + + /* Applies to the element with <... id="someid"> specified. */ + #someid { color: green; } \ No newline at end of file diff --git a/examples/main.css b/examples/main.css new file mode 100644 index 0000000..7a577a4 --- /dev/null +++ b/examples/main.css @@ -0,0 +1,21 @@ +/* Applies to the entire body of the HTML document (except where overridden by more specific +selectors). */ +body { + margin: 25px; + background-color: rgb(240,240,240); + font-family: arial, sans-serif; + font-size: 14px; + } + + /* Applies to all

...

elements. */ + h1 { + font-size: 35px; + font-weight: normal; + margin-top: 5px; + } + + /* Applies to all elements with <... class="someclass"> specified. */ + .someclass { color: red; } + + /* Applies to the element with <... id="someid"> specified. */ + #someid { color: green; } \ No newline at end of file diff --git a/go.mod b/go.mod index 0066133..5ed485f 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ toolchain go1.23.4 require ( github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 - github.com/h2non/filetype v1.1.3 github.com/sethvargo/go-githubactions v1.3.0 github.com/stretchr/testify v1.10.0 github.com/zeiss/pkg v0.1.19 diff --git a/go.sum b/go.sum index 0110eea..89d11e4 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= -github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6 h1:IsMZxCuZqKuao2vNdfD82fjjgPLfyHLpR41Z88viRWs= github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6/go.mod h1:3VeWNIJaW+O5xpRQbPp0Ybqu1vJd/pm7s2F473HRrkw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/main.go b/main.go index 60fa562..07ed012 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,8 @@ package main import ( "context" - "errors" - "io" "io/fs" + "mime" "os" "path/filepath" @@ -13,41 +12,50 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob" - "github.com/h2non/filetype" "github.com/sethvargo/go-githubactions" "github.com/zeiss/pkg/cast" "github.com/zeiss/pkg/utilx" ) // GetContentType ... -func GetContentType(seeker io.ReadSeeker) (string, error) { - // At most the first 512 bytes of data are used: - // https://golang.org/src/net/http/sniff.go?s=646:688#L11 - buff := make([]byte, 512) - - _, err := seeker.Seek(0, io.SeekStart) - if err != nil { - return "", err +func GetContentType(file string) string { + ext := filepath.Ext(file) + switch ext { + case ".htm", ".html": + return "text/html" + case ".css": + return "text/css" + case ".js": + return "application/javascript" + default: + return mime.TypeByExtension(ext) } - bytesRead, err := seeker.Read(buff) - if utilx.NotEmpty(err) && !errors.Is(err, io.EOF) { - return "", err - } + // // At most the first 512 bytes of data are used: + // // https://golang.org/src/net/http/sniff.go?s=646:688#L11 + // buff := make([]byte, 512) - // Slice to remove fill-up zero values which cause a wrong content type detection in the next step - buff = buff[:bytesRead] + // _, err := seeker.Seek(0, io.SeekStart) + // if err != nil { + // return "", err + // } - kind, err := filetype.Match(buff) - if err != nil && !errors.Is(err, filetype.ErrEmptyBuffer) { - return "", err - } + // bytesRead, err := seeker.Read(buff) + // if utilx.NotEmpty(err) && !errors.Is(err, io.EOF) { + // return "", err + // } - if errors.Is(err, filetype.ErrEmptyBuffer) { - return "application/octet-stream", nil - } + // // Slice to remove fill-up zero values which cause a wrong content type detection in the next step + // buff = buff[:bytesRead] - return kind.MIME.Type, nil + // // Special override for unknown file types + // ext := filepath.Ext(file) + // switch ext { + // case ".css": + // return "text/css", nil + // } + + // return http.DetectContentType(buff), nil } // nolint:gocyclo @@ -90,18 +98,15 @@ func main() { return err } - kind, err := GetContentType(file) - if err != nil { - return err - } + ct := GetContentType(path) opts := &azblob.UploadFileOptions{ HTTPHeaders: &blob.HTTPHeaders{ - BlobContentType: cast.Ptr(kind), + BlobContentType: cast.Ptr(ct), }, } - githubactions.Infof("uploading %s (%s)", p, kind) + githubactions.Infof("uploading %s (%s)", p, ct) _, err = client.UploadFile(ctx, cfg.ContainerName, p, file, opts) if err != nil {