refactor: add tus uploads to the pins response

This commit is contained in:
Derrick Hammer 2024-03-28 17:52:01 -04:00
parent a54238d4b6
commit a16390ccc1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 34 additions and 1 deletions

View File

@ -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})
}