Compare commits
No commits in common. "7fe05862b1af652dff30fcf3428795e17aa2884a" and "6ddef03790971e346fa0a7d33a462f39348bc6cc" have entirely different histories.
7fe05862b1
...
6ddef03790
|
@ -26,7 +26,7 @@ func (f *FilesController) PostUpload() {
|
|||
return
|
||||
}
|
||||
|
||||
upload, err := files.Upload(file, meta.Size, nil)
|
||||
upload, err := files.Upload(file, meta.Size)
|
||||
|
||||
if internalError(ctx, err) {
|
||||
shared.GetLogger().Debug("failed uploading file", zap.Error(err))
|
||||
|
|
4
go.mod
4
go.mod
|
@ -18,9 +18,9 @@ require (
|
|||
gitlab.com/NebulousLabs/encoding v0.0.0-20200604091946-456c3dc907fe
|
||||
go.sia.tech/core v0.1.12-0.20230503202148-581dd00ac1d2
|
||||
go.sia.tech/jape v0.9.0
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230520152334-e004ada9c4e9
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230516200305-8097423dbe64
|
||||
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca
|
||||
go.sia.tech/web/renterd v0.17.0
|
||||
go.sia.tech/web/renterd v0.15.0
|
||||
go.uber.org/zap v1.24.0
|
||||
golang.org/x/crypto v0.8.0
|
||||
golang.org/x/term v0.8.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1206,16 +1206,12 @@ go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU=
|
|||
go.sia.tech/mux v1.2.0/go.mod h1:Yyo6wZelOYTyvrHmJZ6aQfRoer3o4xyKQ4NmQLJrBSo=
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230516200305-8097423dbe64 h1:qA+aREwc+i8Q56F9VL9wdxagmtoPKcAd6MVZKOt0JRI=
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230516200305-8097423dbe64/go.mod h1:jFxggAqLQ9fs85iLpC7s2Xnit3rTx7AajW37LgR1vQs=
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230520152334-e004ada9c4e9 h1:jfxmpr/8UG9IDoU/vA4Jqq2cqWT9SsDJv06uZ48W/qs=
|
||||
go.sia.tech/renterd v0.3.0-beta.0.20230520152334-e004ada9c4e9/go.mod h1:ln0uIpeEvgd0lhDx1yB2+u6WXUMermu1QO6lI96xJKI=
|
||||
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca h1:aZMg2AKevn7jKx+wlusWQfwSM5pNU9aGtRZme29q3O4=
|
||||
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca/go.mod h1:h/1afFwpxzff6/gG5i1XdAgPK7dEY6FaibhK7N5F86Y=
|
||||
go.sia.tech/web/renterd v0.14.0 h1:74WDPNYXk71d8uT86rkQAa7AlDp8+VDRsQ2oyhwPplg=
|
||||
go.sia.tech/web/renterd v0.14.0/go.mod h1:jr4PVQW1KU8JpAzmJRfFecDeJ5SPIRrKM3OKZ+FvGvE=
|
||||
go.sia.tech/web/renterd v0.15.0 h1:GeaXbvrgcq1RseRMmHFlHW8LkfPLfANwYvr2XKwpHQI=
|
||||
go.sia.tech/web/renterd v0.15.0/go.mod h1:jr4PVQW1KU8JpAzmJRfFecDeJ5SPIRrKM3OKZ+FvGvE=
|
||||
go.sia.tech/web/renterd v0.17.0 h1:s1k/R9Mbuxq1aRFN+C0ASmLP7/BvQRCpPBqbYFBv7wc=
|
||||
go.sia.tech/web/renterd v0.17.0/go.mod h1:jr4PVQW1KU8JpAzmJRfFecDeJ5SPIRrKM3OKZ+FvGvE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
type Tus struct {
|
||||
gorm.Model
|
||||
ID uint64 `gorm:"primaryKey"`
|
||||
UploadID string
|
||||
UploadID string `gorm:"primaryKey"`
|
||||
Id string
|
||||
Hash string
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package files
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
@ -26,7 +25,7 @@ func Init() {
|
|||
client.SetDisableWarn(true)
|
||||
}
|
||||
|
||||
func Upload(r io.ReadSeeker, size int64, hash []byte) (model.Upload, error) {
|
||||
func Upload(r io.ReadSeeker, size int64) (model.Upload, error) {
|
||||
var upload model.Upload
|
||||
|
||||
tree, hashBytes, err := bao.ComputeTree(r, size)
|
||||
|
@ -36,13 +35,6 @@ func Upload(r io.ReadSeeker, size int64, hash []byte) (model.Upload, error) {
|
|||
return upload, err
|
||||
}
|
||||
|
||||
if hash != nil {
|
||||
if bytes.Compare(hashBytes[:], hash) != 0 {
|
||||
shared.GetLogger().Error("File hash does not match provided file hash")
|
||||
return upload, err
|
||||
}
|
||||
}
|
||||
|
||||
hashHex := hex.EncodeToString(hashBytes[:])
|
||||
|
||||
_, err = r.Seek(0, io.SeekStart)
|
||||
|
@ -58,11 +50,6 @@ func Upload(r io.ReadSeeker, size int64, hash []byte) (model.Upload, error) {
|
|||
shared.GetLogger().Error("Failed to query uploads table", zap.Error(err))
|
||||
return upload, err
|
||||
}
|
||||
|
||||
if result.RowsAffected > 0 && upload.ID > 0 {
|
||||
shared.GetLogger().Info("Upload already exists")
|
||||
return upload, nil
|
||||
}
|
||||
}
|
||||
|
||||
objectExistsResult, err := client.R().Get(fmt.Sprintf("/worker/objects/%s", hashHex))
|
||||
|
@ -135,7 +122,7 @@ func Download(hash string) (io.Reader, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
upload, err := shared.GetTusStore().GetUpload(context.Background(), tusData.UploadID)
|
||||
upload, err := shared.GetTusStore().GetUpload(context.Background(), tusData.Id)
|
||||
if err != nil {
|
||||
shared.GetLogger().Error("Failed querying tus upload", zap.Error(err))
|
||||
return nil, err
|
||||
|
|
50
tus/tus.go
50
tus/tus.go
|
@ -79,7 +79,7 @@ func Init() *tusd.Handler {
|
|||
},
|
||||
PreFinishResponseCallback: func(hook tusd.HookEvent) error {
|
||||
tusEntry := &model.Tus{
|
||||
UploadID: hook.Upload.ID,
|
||||
Id: hook.Upload.ID,
|
||||
Hash: hook.Upload.MetaData[HASH_META_HEADER],
|
||||
}
|
||||
|
||||
|
@ -147,26 +147,32 @@ func tusWorker(upload *tusd.Upload) error {
|
|||
return err
|
||||
}
|
||||
|
||||
hashHex := info.MetaData[HASH_META_HEADER]
|
||||
|
||||
hashBytes, err := hex.DecodeString(hashHex)
|
||||
|
||||
_, err = files.Upload(file.(io.ReadSeeker), info.Size)
|
||||
if err != nil {
|
||||
shared.GetLogger().Error("failed decoding hash", zap.Error(err))
|
||||
tErr := terminateUpload(*upload)
|
||||
|
||||
if tErr != nil {
|
||||
return tErr
|
||||
err1 := terminateUpload(*upload)
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = files.Upload(file.(io.ReadSeeker), info.Size, hashBytes)
|
||||
tErr := terminateUpload(*upload)
|
||||
hash := info.MetaData[HASH_META_HEADER]
|
||||
|
||||
if tErr != nil {
|
||||
return tErr
|
||||
var tusUpload model.Tus
|
||||
ret := db.Get().Where(&model.Tus{Hash: hash}).First(&tusUpload)
|
||||
|
||||
if ret.Error != nil && ret.Error.Error() != "record not found" {
|
||||
shared.GetLogger().Error("failed fetching tus entry", zap.Error(err))
|
||||
err1 := terminateUpload(*upload)
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
_ = db.Get().Delete(&tusUpload)
|
||||
|
||||
err = terminateUpload(*upload)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -176,26 +182,10 @@ func tusWorker(upload *tusd.Upload) error {
|
|||
}
|
||||
|
||||
func terminateUpload(upload tusd.Upload) error {
|
||||
info, _ := upload.GetInfo(context.Background())
|
||||
err := shared.GetTusComposer().Terminater.AsTerminatableUpload(upload).Terminate(context.Background())
|
||||
|
||||
if err != nil {
|
||||
shared.GetLogger().Error("failed deleting tus upload", zap.Error(err))
|
||||
}
|
||||
|
||||
tusUpload := &model.Tus{UploadID: info.ID}
|
||||
ret := db.Get().Where(tusUpload).First(&tusUpload)
|
||||
|
||||
if ret.Error != nil && ret.Error.Error() != "record not found" {
|
||||
shared.GetLogger().Error("failed fetching tus entry", zap.Error(err))
|
||||
err = ret.Error
|
||||
}
|
||||
|
||||
err1 := db.Get().Where(&tusUpload).Delete(&tusUpload)
|
||||
|
||||
_ = err1
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue