Compare commits

..

2 Commits

2 changed files with 45 additions and 1 deletions

View File

@ -865,7 +865,13 @@ func (s *S5API) accountPins(jc jape.Context) {
return 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 { for i, pin := range pinsRet {
cid, err := encoding.CIDFromHash(pin.Upload.Hash, pin.Upload.Size, types.CIDTypeRaw, types.HashTypeBlake3) 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}) jc.Encode(&AccountPinResponse{Pins: pins})
} }

View File

@ -175,6 +175,17 @@ func (t *TusHandler) UploadExists(ctx context.Context, hash []byte) (bool, model
return result.RowsAffected > 0, upload return result.RowsAffected > 0, upload
} }
func (t *TusHandler) Uploads(ctx context.Context, uploaderID uint) ([]models.TusUpload, error) {
var uploads []models.TusUpload
result := t.db.WithContext(ctx).Model(&models.TusUpload{}).Where(&models.TusUpload{UploaderID: uploaderID}).Find(&uploads)
if result.Error != nil {
return nil, result.Error
}
return uploads, nil
}
func (t *TusHandler) CreateUpload(ctx context.Context, hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) { func (t *TusHandler) CreateUpload(ctx context.Context, hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) {
upload := &models.TusUpload{ upload := &models.TusUpload{
Hash: hash, Hash: hash,