Compare commits

..

2 Commits

1 changed files with 4 additions and 3 deletions

View File

@ -26,7 +26,7 @@ func Init() {
func Upload(r io.ReadSeeker) (model.Upload, error) { func Upload(r io.ReadSeeker) (model.Upload, error) {
var upload model.Upload var upload model.Upload
hasher := blake3.New(0, nil) hasher := blake3.New(32, nil)
_, err := io.Copy(hasher, r) _, err := io.Copy(hasher, r)
if err != nil { if err != nil {
@ -34,6 +34,7 @@ func Upload(r io.ReadSeeker) (model.Upload, error) {
} }
hashBytes := hasher.Sum(nil) hashBytes := hasher.Sum(nil)
hashHex := hex.EncodeToString(hashBytes[:]) hashHex := hex.EncodeToString(hashBytes[:])
if err != nil { if err != nil {
@ -45,7 +46,7 @@ func Upload(r io.ReadSeeker) (model.Upload, error) {
return upload, err return upload, err
} }
result := db.Get().Where("hash = ?", hashHex).First(&upload) result := db.Get().Where(&model.Upload{Hash: hashHex}).First(&upload)
if (result.Error != nil && result.Error.Error() != "record not found") || result.RowsAffected > 0 { if (result.Error != nil && result.Error.Error() != "record not found") || result.RowsAffected > 0 {
err := result.Row().Scan(&upload) err := result.Row().Scan(&upload)
if err != nil { if err != nil {
@ -97,7 +98,7 @@ func Upload(r io.ReadSeeker) (model.Upload, error) {
return upload, nil return upload, nil
} }
func Download(hash string) (io.Reader, error) { func Download(hash string) (io.Reader, error) {
result := db.Get().Table("uploads").Where("hash = ?", hash).Row() result := db.Get().Table("uploads").Where(&model.Upload{Hash: hash}).Row()
if result.Err() != nil { if result.Err() != nil {
return nil, result.Err() return nil, result.Err()