feat: implement /s5/pin/:cid/status
This commit is contained in:
parent
7696997e53
commit
0a85711ead
|
@ -133,3 +133,8 @@ type AccountPin struct {
|
|||
PinnedAt time.Time `json:"pinned_at"`
|
||||
MimeType string `json:"mime_type"`
|
||||
}
|
||||
|
||||
type AccountPinStatusResponse struct {
|
||||
Status models.ImportStatus `json:"status"`
|
||||
Progress float64 `json:"progress"`
|
||||
}
|
||||
|
|
32
api/s5/s5.go
32
api/s5/s5.go
|
@ -1141,7 +1141,39 @@ func (s *S5API) accountPin(jc jape.Context) {
|
|||
}
|
||||
|
||||
func (s *S5API) accountPinStatus(jc jape.Context) {
|
||||
var cid string
|
||||
if err := jc.DecodeParam("cid", &cid); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
userID := middleware.GetUserFromContext(jc.Request.Context())
|
||||
|
||||
decodedCid, err := encoding.CIDFromString(cid)
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInvalidOperation, err))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.accounts.PinByHash(decodedCid.Hash.HashBytes(), userID); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyResourceNotFound, err))
|
||||
return
|
||||
}
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyInternalError, err))
|
||||
return
|
||||
}
|
||||
|
||||
meta, err := s._import.GetImport(jc.Request.Context(), decodedCid.Hash.HashBytes())
|
||||
|
||||
if err != nil {
|
||||
s.sendErrorResponse(jc, NewS5Error(ErrKeyResourceNotFound, err))
|
||||
return
|
||||
}
|
||||
|
||||
jc.Encode(&AccountPinStatusResponse{
|
||||
Status: meta.Status,
|
||||
Progress: meta.Progress,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *S5API) pinEntity(ctx context.Context, userId uint, userIp string, cid *encoding.CID) error {
|
||||
|
|
|
@ -679,6 +679,24 @@ paths:
|
|||
responses:
|
||||
'204':
|
||||
description: File pinned
|
||||
/s5/pin/{cid}/status:
|
||||
get:
|
||||
summary: Retrieve pin status
|
||||
tags:
|
||||
- pin
|
||||
parameters:
|
||||
- name: cid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Pin status
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/AccountPinStatusResponse'
|
||||
/s5/delete/{cid}:
|
||||
delete:
|
||||
summary: Delete a file. This will only unpin it from the account, and potentially delete it later if there are no more global pins.
|
||||
|
@ -923,6 +941,16 @@ components:
|
|||
type: string
|
||||
mime_type:
|
||||
type: string
|
||||
AccountPinStatusResponse:
|
||||
type: object
|
||||
required:
|
||||
- status
|
||||
- progress
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
progress:
|
||||
type: number
|
||||
RegistryQueryResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
|
Loading…
Reference in New Issue