Compare commits
2 Commits
85a02952df
...
3b1e860256
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 3b1e860256 | |
Derrick Hammer | 160a9f7ebb |
|
@ -84,6 +84,31 @@ func (f *FilesController) GetDownloadBy(cidString string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (f *FilesController) GetProofBy(cidString string) {
|
||||
ctx := f.Ctx
|
||||
|
||||
hashHex, valid := validateCid(cidString, true, ctx)
|
||||
|
||||
if !valid {
|
||||
return
|
||||
}
|
||||
|
||||
download, err := files.DownloadProof(hashHex)
|
||||
if internalError(ctx, err) {
|
||||
logger.Get().Debug("failed fetching file proof", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
err = ctx.StreamWriter(func(w io.Writer) error {
|
||||
_, err = io.Copy(w, download)
|
||||
_ = download.(io.Closer).Close()
|
||||
return err
|
||||
})
|
||||
if internalError(ctx, err) {
|
||||
logger.Get().Debug("failed streaming file proof", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FilesController) GetStatusBy(cidString string) {
|
||||
ctx := f.Ctx
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ func Download(hash string) (io.Reader, error) {
|
|||
tusItem := db.Get().Table("tus").Where(&model.Tus{Hash: hash}).Row()
|
||||
|
||||
if uploadItem.Err() == nil {
|
||||
fetch, err := client.R().SetDoNotParseResponse(true).Get(fmt.Sprintf("/worker/objects/%s", hash))
|
||||
fetch, err := client.R().SetDoNotParseResponse(true).Get(getWorkerProofUrl(hash))
|
||||
if err != nil {
|
||||
logger.Get().Error(ErrFailedFetchObject.Error(), zap.Error(err))
|
||||
return nil, ErrFailedFetchObject
|
||||
|
@ -198,6 +198,22 @@ func Download(hash string) (io.Reader, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func DownloadProof(hash string) (io.Reader, error) {
|
||||
uploadItem := db.Get().Model(&model.Upload{}).Where(&model.Upload{Hash: hash}).Row()
|
||||
|
||||
if uploadItem.Err() != nil {
|
||||
logger.Get().Debug(ErrInvalidFile.Error(), zap.String("hash", hash))
|
||||
return nil, ErrInvalidFile
|
||||
}
|
||||
fetch, err := client.R().SetDoNotParseResponse(true).Get(getWorkerProofUrl(hash))
|
||||
if err != nil {
|
||||
logger.Get().Error(ErrFailedFetchObject.Error(), zap.Error(err))
|
||||
return nil, ErrFailedFetchObject
|
||||
}
|
||||
|
||||
return fetch.RawBody(), nil
|
||||
}
|
||||
|
||||
func Status(hash string) int {
|
||||
var count int64
|
||||
|
||||
|
|
Loading…
Reference in New Issue