fix: uploading of main file
This commit is contained in:
parent
5aca66d919
commit
7aea462ab7
|
@ -40,14 +40,16 @@ func (f *FilesService) PostUpload() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf, err := io.ReadAll(file)
|
||||||
_, err = buf.ReadFrom(file)
|
if internalError(ctx, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if internalErrorCustom(ctx, err, errors.New("failed to read file data")) {
|
if internalErrorCustom(ctx, err, errors.New("failed to read file data")) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hashBytes := blake3.Sum256(buf.Bytes())
|
hashBytes := blake3.Sum256(buf)
|
||||||
hashHex := hex.EncodeToString(hashBytes[:])
|
hashHex := hex.EncodeToString(hashBytes[:])
|
||||||
fileCid, err := cid.EncodeHashSimple(hashBytes, uint64(meta.Size))
|
fileCid, err := cid.EncodeHashSimple(hashBytes, uint64(meta.Size))
|
||||||
|
|
||||||
|
@ -55,6 +57,11 @@ func (f *FilesService) PostUpload() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = file.Seek(0, io.SeekStart)
|
||||||
|
if internalError(ctx, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var upload model.Upload
|
var upload model.Upload
|
||||||
result := db.Get().Where("hash = ?", hashHex).First(&upload)
|
result := db.Get().Where("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 {
|
||||||
|
@ -67,7 +74,7 @@ func (f *FilesService) PostUpload() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tree, err := bao.ComputeBaoTree(file)
|
tree, err := bao.ComputeBaoTree(bytes.NewReader(buf))
|
||||||
if internalError(ctx, err) {
|
if internalError(ctx, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -83,7 +90,11 @@ func (f *FilesService) PostUpload() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := client.R().SetBody(file).Put(fmt.Sprintf("/worker/objects/%s", hashHex))
|
if internalError(ctx, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, err := client.R().SetBody(buf).Put(fmt.Sprintf("/worker/objects/%s", hashHex))
|
||||||
if ret.StatusCode() != 200 {
|
if ret.StatusCode() != 200 {
|
||||||
err = errors.New(string(ret.Body()))
|
err = errors.New(string(ret.Body()))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue