refactor: add Download function to files service

This commit is contained in:
Derrick Hammer 2023-05-10 14:41:12 -04:00
parent 73bc836cbc
commit b48db1d8c4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 0 deletions

View File

@ -95,3 +95,17 @@ func Upload(r io.ReadSeeker) (model.Upload, error) {
return upload, nil return upload, nil
} }
func Download(hash string) (io.Reader, error) {
result := db.Get().Table("uploads").Where("hash = ?", hash).Row()
if result.Err() != nil {
return nil, result.Err()
}
fetch, err := client.R().SetDoNotParseResponse(true).Get(fmt.Sprintf("/worker/objects/%s", hash))
if err != nil {
return nil, err
}
return fetch.RawBody(), nil
}