refactor: switch to using a Params struct and store Renter

This commit is contained in:
Derrick Hammer 2024-02-09 15:42:53 -05:00
parent e7ac46de32
commit 28d966cbe2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 17 additions and 3 deletions

View File

@ -1,11 +1,14 @@
package storage
import (
"context"
"encoding/hex"
"errors"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/portal/db/models"
"git.lumeweb.com/LumeWeb/portal/renter"
"go.sia.tech/renterd/api"
"io"
"time"
)
@ -14,13 +17,20 @@ type FileImpl struct {
reader io.ReadCloser
hash []byte
storage *StorageServiceDefault
renter *renter.RenterDefault
record *models.Upload
cid *encoding.CID
read bool
}
func NewFile(hash []byte, storage *StorageServiceDefault) *FileImpl {
return &FileImpl{hash: hash, storage: storage, read: false}
type FileParams struct {
Storage *StorageServiceDefault
Renter *renter.RenterDefault
Hash []byte
}
func NewFile(params FileParams) *FileImpl {
return &FileImpl{hash: params.Hash, storage: params.Storage, renter: params.Renter, read: false}
}
func (f *FileImpl) Exists() bool {

View File

@ -667,5 +667,9 @@ func (s *StorageServiceDefault) GetFile(hash []byte, start int64) (io.ReadCloser
return object.Content, int64(upload.Size), nil
}
func (s *StorageServiceDefault) NewFile(hash []byte) *FileImpl {
return NewFile(hash, s)
return NewFile(FileParams{
Storage: s,
Renter: s.renter,
Hash: hash,
})
}