feat: handle existing files

This commit is contained in:
Derrick Hammer 2024-01-16 01:05:09 -05:00
parent a4e0e1fa58
commit 276719f47f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 26 additions and 1 deletions

View File

@ -88,7 +88,32 @@ func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) {
}(r.Body)
}
hash, err := h.portal.Storage().PutFile(rs, "s5", false)
hash, err := h.portal.Storage().GetHash(rs)
if err != nil {
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
h.portal.Logger().Error(errUploadingFile, zap.Error(err))
return
}
if exists, upload := h.portal.Storage().FileExists(hash); exists {
cid, err := encoding.CIDFromHash(hash, upload.Size, types.CIDTypeRaw)
if err != nil {
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
h.portal.Logger().Error(errUploadingFile, zap.Error(err))
return
}
cidStr, err := cid.ToString()
if err != nil {
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
h.portal.Logger().Error(errUploadingFile, zap.Error(err))
return
}
jc.Encode(map[string]string{"hash": cidStr})
return
}
hash, err = h.portal.Storage().PutFile(rs, "s5", false)
if err != nil {
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)