From 28d966cbe2eb5852877886a2a2292709dce70843 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Feb 2024 15:42:53 -0500 Subject: [PATCH] refactor: switch to using a Params struct and store Renter --- storage/file.go | 14 ++++++++++++-- storage/storage.go | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/storage/file.go b/storage/file.go index 5acd15b..95ce689 100644 --- a/storage/file.go +++ b/storage/file.go @@ -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 { diff --git a/storage/storage.go b/storage/storage.go index d8fc70f..0a9778a 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -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, + }) }