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 package storage
import ( import (
"context"
"encoding/hex" "encoding/hex"
"errors" "errors"
"git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/portal/db/models" "git.lumeweb.com/LumeWeb/portal/db/models"
"git.lumeweb.com/LumeWeb/portal/renter"
"go.sia.tech/renterd/api"
"io" "io"
"time" "time"
) )
@ -14,13 +17,20 @@ type FileImpl struct {
reader io.ReadCloser reader io.ReadCloser
hash []byte hash []byte
storage *StorageServiceDefault storage *StorageServiceDefault
renter *renter.RenterDefault
record *models.Upload record *models.Upload
cid *encoding.CID cid *encoding.CID
read bool read bool
} }
func NewFile(hash []byte, storage *StorageServiceDefault) *FileImpl { type FileParams struct {
return &FileImpl{hash: hash, storage: storage, read: false} 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 { 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 return object.Content, int64(upload.Size), nil
} }
func (s *StorageServiceDefault) NewFile(hash []byte) *FileImpl { func (s *StorageServiceDefault) NewFile(hash []byte) *FileImpl {
return NewFile(hash, s) return NewFile(FileParams{
Storage: s,
Renter: s.renter,
Hash: hash,
})
} }