Skip to content

Commit

Permalink
chore: have a default type
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jan 8, 2025
1 parent fe24fb3 commit 99dc272
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
13 changes: 13 additions & 0 deletions examples/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>

<head>
<title>This is the title of the webpage!</title>
</head>

<body>
<p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this
<strong>p</strong> tag and its contents.</p>
</body>

</html>
13 changes: 13 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>

<head>
<title>This is the title of the webpage!</title>
</head>

<body>
<p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this
<strong>p</strong> tag and its contents.</p>
</body>

</html>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"errors"
"io"
"io/fs"
"net/http"
"os"
"path/filepath"
"strings"

"template/internal/cfg"

"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"
Expand All @@ -39,7 +38,16 @@ func GetContentType(seeker io.ReadSeeker) (string, error) {
// Slice to remove fill-up zero values which cause a wrong content type detection in the next step
buff = buff[:bytesRead]

return http.DetectContentType(buff), nil
kind, err := filetype.Match(buff)
if err != nil && !errors.Is(err, filetype.ErrEmptyBuffer) {
return "", err
}

if errors.Is(err, filetype.ErrEmptyBuffer) {
return "application/octet-stream", nil
}

return kind.MIME.Type, nil
}

// nolint:gocyclo
Expand Down Expand Up @@ -82,21 +90,18 @@ func main() {
return err
}

ct, err := GetContentType(file)
kind, err := GetContentType(file)
if err != nil {
return err
}

cts := strings.SplitN(ct, ";", 2)
c := strings.TrimSpace(cts[0])

opts := &azblob.UploadFileOptions{
HTTPHeaders: &blob.HTTPHeaders{
BlobContentType: cast.Ptr(c),
BlobContentType: cast.Ptr(kind),
},
}

githubactions.Infof("uploading %s (%s)", p, c)
githubactions.Infof("uploading %s (%s)", p, kind)

_, err = client.UploadFile(ctx, cfg.ContainerName, p, file, opts)
if err != nil {
Expand Down

0 comments on commit 99dc272

Please sign in to comment.