refactor: change newFile to take the params struct directly and fill in the blanks

This commit is contained in:
Derrick Hammer 2024-03-01 21:59:49 -05:00
parent 65548e8ec7
commit a1f36df8b9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 9 deletions

View File

@ -1678,7 +1678,10 @@ func (s *S5API) downloadFile(jc jape.Context) {
hashBytes = cidDecoded.Hash.HashBytes() hashBytes = cidDecoded.Hash.HashBytes()
} }
file := s.newFile(s.protocol, hashBytes, cidDecoded.Type) file := s.newFile(FileParams{
Hash: cidDecoded.Hash.HashBytes(),
Type: cidDecoded.Type,
})
if !file.Exists() { if !file.Exists() {
jc.ResponseWriter.WriteHeader(http.StatusNotFound) jc.ResponseWriter.WriteHeader(http.StatusNotFound)
@ -1751,14 +1754,12 @@ func (s *S5API) newStorageLocationProvider(hash *encoding.Multihash, excludeSelf
}) })
} }
func (s *S5API) newFile(protocol *s5.S5Protocol, hash []byte, cidTyp types.CIDType) *S5File { func (s *S5API) newFile(params FileParams) *S5File {
return NewFile(FileParams{ params.Protocol = s.protocol
Protocol: protocol, params.Metadata = s.metadata
Hash: hash, params.Storage = s.storage
Metadata: s.metadata,
Storage: s.storage, return NewFile(params)
Type: cidTyp,
})
} }
func (s *S5API) pinImportCronJob(cid string, url string, proofUrl string, userId uint) error { func (s *S5API) pinImportCronJob(cid string, url string, proofUrl string, userId uint) error {