refactor: fix pinning logic if file exists
This commit is contained in:
parent
0caa54f028
commit
f2c68857f2
18
api/s5/s5.go
18
api/s5/s5.go
|
@ -1119,18 +1119,14 @@ func (s *S5API) accountPin(jc jape.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cids, err := s.getManifestCids(jc.Request.Context(), decodedCid, false)
|
if isCidManifest(decodedCid) {
|
||||||
if err != nil {
|
cids, err := s.getManifestCids(jc.Request.Context(), decodedCid, false)
|
||||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
|
if err != nil {
|
||||||
return
|
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
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))
|
||||||
|
|
Loading…
Reference in New Issue