feat: add upload create call

This commit is contained in:
Derrick Hammer 2024-01-16 02:01:18 -05:00
parent cc5fadeef3
commit 185269afea
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 0 deletions

View File

@ -2,10 +2,12 @@ package s5
import ( import (
"bytes" "bytes"
"encoding/hex"
"errors" "errors"
"git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/encoding"
s5interface "git.lumeweb.com/LumeWeb/libs5-go/interfaces" s5interface "git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/portal/db/models"
"git.lumeweb.com/LumeWeb/portal/interfaces" "git.lumeweb.com/LumeWeb/portal/interfaces"
"go.sia.tech/jape" "go.sia.tech/jape"
"go.uber.org/zap" "go.uber.org/zap"
@ -137,5 +139,18 @@ func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) {
return return
} }
tx := h.portal.Database().Create(&models.Upload{
Hash: hex.EncodeToString(hash),
Size: uint64(bufferSize),
Protocol: "s5",
UserID: 0,
})
if tx.Error != nil {
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
h.portal.Logger().Error(errUploadingFile, zap.Error(err))
return
}
jc.Encode(map[string]string{"hash": cidStr}) jc.Encode(map[string]string{"hash": cidStr})
} }