Compare commits
No commits in common. "09c9ab8614d499cfcc6ba6453cdb90bd4498def5" and "aeba225c87119087077fe88a9f6b68debe341553" have entirely different histories.
09c9ab8614
...
aeba225c87
21
api/s5/s5.go
21
api/s5/s5.go
|
@ -22,8 +22,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
|
|
||||||
_import "git.lumeweb.com/LumeWeb/portal/import"
|
_import "git.lumeweb.com/LumeWeb/portal/import"
|
||||||
|
|
||||||
"git.lumeweb.com/LumeWeb/portal/api/router"
|
"git.lumeweb.com/LumeWeb/portal/api/router"
|
||||||
|
@ -1993,27 +1991,10 @@ func (s *S5API) downloadFile(jc jape.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var mimeType string
|
|
||||||
|
|
||||||
if len(file.Mime()) > 0 {
|
if len(file.Mime()) > 0 {
|
||||||
mimeType = file.Mime()
|
jc.ResponseWriter.Header().Set("Content-Type", file.Mime())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(mimeType) == 0 {
|
|
||||||
detectedType, err := mimetype.DetectReader(file)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("error detecting mime type", zap.Error(err))
|
|
||||||
}
|
|
||||||
_ = jc.Error(err, http.StatusInternalServerError)
|
|
||||||
mimeType = detectedType.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(mimeType) == 0 {
|
|
||||||
mimeType = "application/octet-stream"
|
|
||||||
}
|
|
||||||
|
|
||||||
jc.ResponseWriter.Header().Set("Content-Type", mimeType)
|
|
||||||
|
|
||||||
http.ServeContent(jc.ResponseWriter, jc.Request, file.Name(), file.Modtime(), file)
|
http.ServeContent(jc.ResponseWriter, jc.Request, file.Name(), file.Modtime(), file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -14,12 +14,10 @@ require (
|
||||||
github.com/ddo/rq v0.0.0-20190828174524-b3daa55fcaba
|
github.com/ddo/rq v0.0.0-20190828174524-b3daa55fcaba
|
||||||
github.com/dnslink-std/go v0.6.0
|
github.com/dnslink-std/go v0.6.0
|
||||||
github.com/docker/go-units v0.5.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/getkin/kin-openapi v0.118.0
|
||||||
github.com/go-co-op/gocron/v2 v2.2.4
|
github.com/go-co-op/gocron/v2 v2.2.4
|
||||||
github.com/go-gorm/caches/v4 v4.0.0
|
github.com/go-gorm/caches/v4 v4.0.0
|
||||||
github.com/go-resty/resty/v2 v2.11.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-jwt/jwt/v5 v5.2.0
|
||||||
github.com/golang-queue/queue v0.2.0
|
github.com/golang-queue/queue v0.2.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
@ -77,6 +75,7 @@ require (
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.20.2 // indirect
|
github.com/go-openapi/jsonpointer v0.20.2 // indirect
|
||||||
github.com/go-openapi/swag v0.22.8 // 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/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/gorilla/websocket v1.5.1 // indirect
|
github.com/gorilla/websocket v1.5.1 // indirect
|
||||||
github.com/hashicorp/go-hclog v1.6.2 // indirect
|
github.com/hashicorp/go-hclog v1.6.2 // indirect
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -37,7 +38,6 @@ import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"git.lumeweb.com/LumeWeb/portal/renter"
|
"git.lumeweb.com/LumeWeb/portal/renter"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const PROOF_EXTENSION = ".obao"
|
const PROOF_EXTENSION = ".obao"
|
||||||
|
@ -166,12 +166,13 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
||||||
return &meta, nil
|
return &meta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mimeBytes := make([]byte, 512)
|
||||||
|
|
||||||
reader, err = getReader()
|
reader, err = getReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
_, err = io.ReadFull(reader, mimeBytes)
|
||||||
mimeType, err := mimetype.DetectReader(reader)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, io.ErrUnexpectedEOF) {
|
if !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -182,12 +183,7 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
||||||
return nil, err
|
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()
|
reader, err = getReader()
|
||||||
|
@ -195,6 +191,8 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mimeType := http.DetectContentType(mimeBytes)
|
||||||
|
|
||||||
protocolName := protocol.Name()
|
protocolName := protocol.Name()
|
||||||
|
|
||||||
err = s.renter.CreateBucketIfNotExists(protocolName)
|
err = s.renter.CreateBucketIfNotExists(protocolName)
|
||||||
|
@ -213,7 +211,7 @@ func (s StorageServiceDefault) UploadObject(ctx context.Context, protocol Storag
|
||||||
uploadMeta := &metadata.UploadMetadata{
|
uploadMeta := &metadata.UploadMetadata{
|
||||||
Protocol: protocolName,
|
Protocol: protocolName,
|
||||||
Hash: proof.Hash,
|
Hash: proof.Hash,
|
||||||
MimeType: mimeType.String(),
|
MimeType: mimeType,
|
||||||
Size: uint64(proof.Length),
|
Size: uint64(proof.Length),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue