feat: implement a basic account pins json api without paging
This commit is contained in:
parent
8a2f501e8e
commit
ccae147398
|
@ -120,3 +120,12 @@ func (a AccountPinBinaryResponse) EncodeMsgpack(enc *msgpack.Encoder) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
type AccountPinResponse struct {
|
||||
Pins []AccountPin `json:"pins"`
|
||||
}
|
||||
|
||||
type AccountPin struct {
|
||||
Hash string `json:"hash"`
|
||||
MimeType string `json:"mime_type"`
|
||||
}
|
||||
|
|
19
api/s5/s5.go
19
api/s5/s5.go
|
@ -189,6 +189,7 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
|
|||
"GET /s5/account": middleware.ApplyMiddlewares(s.accountInfo, authMw),
|
||||
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.accountStats, authMw),
|
||||
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.accountPinsBinary, authMw),
|
||||
"GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, authMw),
|
||||
|
||||
// Upload API
|
||||
"POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, authMw),
|
||||
|
@ -824,13 +825,27 @@ func (s *S5API) accountPinsBinary(jc jape.Context) {
|
|||
|
||||
func (s *S5API) accountPins(jc jape.Context) {
|
||||
userID := middleware.GetUserFromContext(jc.Request.Context())
|
||||
pins, err := s.accounts.AccountPins(userID, 0)
|
||||
pinsRet, err := s.accounts.AccountPins(userID, 0)
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err))
|
||||
return
|
||||
}
|
||||
|
||||
jc.Encode(&AccountPinBinaryResponse{Pins: pins})
|
||||
pins := make([]AccountPin, len(pinsRet))
|
||||
|
||||
for i, pin := range pinsRet {
|
||||
base64Url, err := encoding.NewMultihash(append([]byte{byte(types.HashTypeBlake3)}, pin.Upload.Hash...)).ToBase64Url()
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInternalError, err))
|
||||
return
|
||||
}
|
||||
pins[i] = AccountPin{
|
||||
Hash: base64Url,
|
||||
MimeType: pin.Upload.MimeType,
|
||||
}
|
||||
}
|
||||
|
||||
jc.Encode(&AccountPinResponse{Pins: pins})
|
||||
}
|
||||
|
||||
func (s *S5API) accountPinDelete(jc jape.Context) {
|
||||
|
|
|
@ -82,6 +82,20 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AccountStatsResponse"
|
||||
/s5/account/pins:
|
||||
get:
|
||||
summary: Retrieve account pins
|
||||
tags:
|
||||
- account
|
||||
responses:
|
||||
'200':
|
||||
description: Account pins
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
/s5/account/pins.bin:
|
||||
get:
|
||||
summary: Retrieve account pins
|
||||
|
@ -882,6 +896,20 @@ components:
|
|||
properties:
|
||||
stats:
|
||||
$ref: "#/components/schemas/AccountStats"
|
||||
AccountPinsResponse:
|
||||
type: object
|
||||
properties:
|
||||
pins:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/AccountPin'
|
||||
AccountPin:
|
||||
type: object
|
||||
properties:
|
||||
hash:
|
||||
type: string
|
||||
mime_type:
|
||||
type: string
|
||||
RegistryQueryResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
|
Loading…
Reference in New Issue