refactor: switch to github.com/gabriel-vasile/mimetype
This commit is contained in:
parent
aeba225c87
commit
8e9d2d0398
3
go.mod
3
go.mod
|
@ -14,10 +14,12 @@ require (
|
|||
github.com/ddo/rq v0.0.0-20190828174524-b3daa55fcaba
|
||||
github.com/dnslink-std/go v0.6.0
|
||||
github.com/docker/go-units v0.5.0
|
||||
github.com/gabriel-vasile/mimetype v1.4.3
|
||||
github.com/getkin/kin-openapi v0.118.0
|
||||
github.com/go-co-op/gocron/v2 v2.2.4
|
||||
github.com/go-gorm/caches/v4 v4.0.0
|
||||
github.com/go-resty/resty/v2 v2.11.0
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||
github.com/golang-queue/queue v0.2.0
|
||||
github.com/google/uuid v1.6.0
|
||||
|
@ -75,7 +77,6 @@ require (
|
|||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.20.2 // indirect
|
||||
github.com/go-openapi/swag v0.22.8 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/hashicorp/go-hclog v1.6.2 // indirect
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
@ -38,6 +37,7 @@ import (
|
|||
"gorm.io/gorm"
|
||||
|
||||
"git.lumeweb.com/LumeWeb/portal/renter"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
)
|
||||
|
||||
const PROOF_EXTENSION = ".obao"
|
||||
|
@ -166,13 +166,12 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
|||
return &meta, nil
|
||||
}
|
||||
|
||||
mimeBytes := make([]byte, 512)
|
||||
|
||||
reader, err = getReader()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = io.ReadFull(reader, mimeBytes)
|
||||
|
||||
mimeType, err := mimetype.DetectReader(reader)
|
||||
if err != nil {
|
||||
if !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
return nil, err
|
||||
|
@ -183,7 +182,12 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mimeBytes, err = io.ReadAll(reader)
|
||||
mimeBytes, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mimeType = mimetype.Detect(mimeBytes)
|
||||
}
|
||||
|
||||
reader, err = getReader()
|
||||
|
@ -191,8 +195,6 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mimeType := http.DetectContentType(mimeBytes)
|
||||
|
||||
protocolName := protocol.Name()
|
||||
|
||||
err = s.renter.CreateBucketIfNotExists(protocolName)
|
||||
|
@ -211,7 +213,7 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
|||
uploadMeta := &metadata.UploadMetadata{
|
||||
Protocol: protocolName,
|
||||
Hash: proof.Hash,
|
||||
MimeType: mimeType,
|
||||
MimeType: mimeType.String(),
|
||||
Size: uint64(proof.Length),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue