refactor: fix pinning logic if file exists

This commit is contained in:
Derrick Hammer 2024-03-22 20:31:44 -04:00
parent 0caa54f028
commit f2c68857f2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 11 deletions

View File

@ -1119,6 +1119,7 @@ func (s *S5API) accountPin(jc jape.Context) {
} }
} }
} else { } else {
if isCidManifest(decodedCid) {
cids, err := s.getManifestCids(jc.Request.Context(), decodedCid, false) cids, err := s.getManifestCids(jc.Request.Context(), decodedCid, false)
if err != nil { if err != nil {
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err)) s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
@ -1126,11 +1127,6 @@ func (s *S5API) accountPin(jc jape.Context) {
} }
for _, cid := range cids { for _, cid := range cids {
if err := s.accounts.PinByHash(cid.Hash.HashBytes(), userID); err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
return
}
err := s.pinEntity(jc.Request.Context(), userID, jc.Request.RemoteAddr, cid) err := s.pinEntity(jc.Request.Context(), userID, jc.Request.RemoteAddr, cid)
if err != nil { if err != nil {
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err)) s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))