Compare commits
No commits in common. "bb26cfca5b4017bbbbf5aeee9bd3577c724f83ca" and "c197b1425bbd689e8f662846de0478aff8d38f35" have entirely different histories.
bb26cfca5b
...
c197b1425b
|
@ -12,8 +12,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errStreamDone = errors.New("done")
|
|
||||||
|
|
||||||
type FilesController struct {
|
type FilesController struct {
|
||||||
Controller
|
Controller
|
||||||
}
|
}
|
||||||
|
@ -76,8 +74,12 @@ func (f *FilesController) GetDownloadBy(cidString string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = passThroughStream(download, ctx)
|
err = ctx.StreamWriter(func(w io.Writer) error {
|
||||||
if err != errStreamDone && internalError(ctx, err) {
|
_, err = io.Copy(w, download)
|
||||||
|
_ = download.(io.Closer).Close()
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if internalError(ctx, err) {
|
||||||
logger.Get().Debug("failed streaming file", zap.Error(err))
|
logger.Get().Debug("failed streaming file", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,13 +93,17 @@ func (f *FilesController) GetProofBy(cidString string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
proof, err := files.DownloadProof(hashHex)
|
download, err := files.DownloadProof(hashHex)
|
||||||
if internalError(ctx, err) {
|
if internalError(ctx, err) {
|
||||||
logger.Get().Debug("failed fetching file proof", zap.Error(err))
|
logger.Get().Debug("failed fetching file proof", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = passThroughStream(proof, ctx)
|
err = ctx.StreamWriter(func(w io.Writer) error {
|
||||||
|
_, err = io.Copy(w, download)
|
||||||
|
_ = download.(io.Closer).Close()
|
||||||
|
return err
|
||||||
|
})
|
||||||
if internalError(ctx, err) {
|
if internalError(ctx, err) {
|
||||||
logger.Get().Debug("failed streaming file proof", zap.Error(err))
|
logger.Get().Debug("failed streaming file proof", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
@ -177,36 +183,3 @@ func validateCid(cidString string, validateStatus bool, ctx iris.Context) (strin
|
||||||
|
|
||||||
return hashHex, true
|
return hashHex, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func passThroughStream(stream io.Reader, ctx iris.Context) error {
|
|
||||||
closed := false
|
|
||||||
|
|
||||||
err := ctx.StreamWriter(func(w io.Writer) error {
|
|
||||||
if closed {
|
|
||||||
return errStreamDone
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err := io.CopyN(w, stream, 1024)
|
|
||||||
if count == 0 || err == io.EOF {
|
|
||||||
err = stream.(io.Closer).Close()
|
|
||||||
if err != nil {
|
|
||||||
logger.Get().Error("failed closing stream", zap.Error(err))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
closed = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if err == errStreamDone {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ func Download(hash string) (io.Reader, error) {
|
||||||
tusItem := db.Get().Table("tus").Where(&model.Tus{Hash: hash}).Row()
|
tusItem := db.Get().Table("tus").Where(&model.Tus{Hash: hash}).Row()
|
||||||
|
|
||||||
if uploadItem.Err() == nil {
|
if uploadItem.Err() == nil {
|
||||||
fetch, err := client.R().SetDoNotParseResponse(true).Get(getWorkerObjectUrl(hash))
|
fetch, err := client.R().SetDoNotParseResponse(true).Get(getWorkerProofUrl(hash))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Get().Error(ErrFailedFetchObject.Error(), zap.Error(err))
|
logger.Get().Error(ErrFailedFetchObject.Error(), zap.Error(err))
|
||||||
return nil, ErrFailedFetchObject
|
return nil, ErrFailedFetchObject
|
||||||
|
|
Loading…
Reference in New Issue