feat: implement /s5/pin/:cid/status

This commit is contained in:
Derrick Hammer 2024-03-22 18:01:12 -04:00
parent 7696997e53
commit 0a85711ead
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 65 additions and 0 deletions

View File

@ -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"`
}

View File

@ -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 {

View File

@ -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: