refactor: add tus uploads to the pins response
This commit is contained in:
parent
a54238d4b6
commit
a16390ccc1
35
api/s5/s5.go
35
api/s5/s5.go
|
@ -865,7 +865,13 @@ func (s *S5API) accountPins(jc jape.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
pins := make([]AccountPin, len(pinsRet))
|
||||
tusRet, err := s.tusHandler.Uploads(jc.Request.Context(), userID)
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
|
||||
return
|
||||
}
|
||||
|
||||
pins := make([]AccountPin, len(pinsRet)+len(tusRet))
|
||||
|
||||
for i, pin := range pinsRet {
|
||||
cid, err := encoding.CIDFromHash(pin.Upload.Hash, pin.Upload.Size, types.CIDTypeRaw, types.HashTypeBlake3)
|
||||
|
@ -886,6 +892,33 @@ func (s *S5API) accountPins(jc jape.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
for i, tus := range tusRet {
|
||||
size, err := s.tusHandler.GetUploadSize(jc.Request.Context(), tus.Hash)
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInternalError, err))
|
||||
return
|
||||
}
|
||||
|
||||
cid, err := encoding.CIDFromHash(tus.Hash, uint64(size), types.CIDTypeRaw, types.HashTypeBlake3)
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInternalError, err))
|
||||
return
|
||||
}
|
||||
|
||||
base64Url, err := cid.Hash.ToBase64Url()
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInternalError, err))
|
||||
return
|
||||
}
|
||||
|
||||
pins[i+len(pinsRet)] = AccountPin{
|
||||
Hash: base64Url,
|
||||
Size: uint64(size),
|
||||
PinnedAt: tus.CreatedAt,
|
||||
MimeType: tus.MimeType,
|
||||
}
|
||||
}
|
||||
|
||||
jc.Encode(&AccountPinResponse{Pins: pins})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue