Skip to content

Commit

Permalink
chore: update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jan 8, 2025
1 parent 614d539 commit a25f888
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 35 deletions.
Binary file modified dist/main-amd64-darwin
Binary file not shown.
Binary file modified dist/main-amd64-linux
Binary file not shown.
Binary file modified dist/main-arm-linux
Binary file not shown.
Binary file modified dist/main-arm64-darwin
Binary file not shown.
Binary file modified dist/main-arm64-linux
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/metadata.json
Original file line number Diff line number Diff line change
@@ -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"}}
{"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"}}
21 changes: 21 additions & 0 deletions examples/demo/main.css
Original file line number Diff line number Diff line change
@@ -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 <h1>...</h1> 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; }
21 changes: 21 additions & 0 deletions examples/main.css
Original file line number Diff line number Diff line change
@@ -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 <h1>...</h1> 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; }
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
67 changes: 36 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"context"
"errors"
"io"
"io/fs"
"mime"
"os"
"path/filepath"

Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a25f888

Please sign in to comment.