mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:34:03 +08:00
coreapi: pin draft
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -58,6 +58,15 @@ type BlockStat interface {
|
||||
Path() Path
|
||||
}
|
||||
|
||||
// Pin holds information about pinned resource
|
||||
type Pin interface {
|
||||
// Path to the pinned object
|
||||
Path() Path
|
||||
|
||||
// Type of the pin
|
||||
Type() string
|
||||
}
|
||||
|
||||
// CoreAPI defines an unified interface to IPFS for Go programs.
|
||||
type CoreAPI interface {
|
||||
// Unixfs returns an implementation of Unixfs API.
|
||||
@ -322,5 +331,40 @@ type ObjectStat struct {
|
||||
CumulativeSize int
|
||||
}
|
||||
|
||||
// PinAPI specifies the interface to pining
|
||||
type PinAPI interface {
|
||||
// Add creates new pin, be default recursive - pinning the whole referenced
|
||||
// tree
|
||||
Add(context.Context, Path, ...options.PinAddOption) error
|
||||
|
||||
// WithRecursive is an option for Add which specifies whether to pin an entire
|
||||
// object tree or just one object. Default: true
|
||||
WithRecursive(bool) options.PinAddOption
|
||||
|
||||
// Ls returns list of pinned objects on this node
|
||||
Ls(context.Context) ([]Pin, error)
|
||||
|
||||
// WithType is an option for Ls which allows to specify which pin types should
|
||||
// be returned
|
||||
//
|
||||
// Supported values:
|
||||
// * "direct" - directly pinned objects
|
||||
// * "recursive" - roots of recursive pins
|
||||
// * "indirect" - indirectly pinned objects (referenced by recursively pinned
|
||||
// objects)
|
||||
// * "all" - all pinned objects (default)
|
||||
WithType(string) options.PinLsOption
|
||||
|
||||
// Rm removes pin for object specified by the path
|
||||
Rm(context.Context, Path) error
|
||||
|
||||
// Update changes one pin to another, skipping checks for matching paths in
|
||||
// the old tree
|
||||
Update(ctx context.Context, from Path, to Path) error
|
||||
|
||||
// Verify verifies the integrity of pinned objects
|
||||
Verify(context.Context) error
|
||||
}
|
||||
|
||||
var ErrIsDir = errors.New("object is a directory")
|
||||
var ErrOffline = errors.New("can't resolve, ipfs node is offline")
|
||||
|
58
core/coreapi/interface/options/pin.go
Normal file
58
core/coreapi/interface/options/pin.go
Normal file
@ -0,0 +1,58 @@
|
||||
package options
|
||||
|
||||
type PinAddSettings struct {
|
||||
Recursive bool
|
||||
}
|
||||
|
||||
type PinLsSettings struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
type PinAddOption func(*PinAddSettings) error
|
||||
type PinLsOption func(settings *PinLsSettings) error
|
||||
|
||||
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
|
||||
options := &PinAddSettings{
|
||||
Recursive: true,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
err := opt(options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return options, nil
|
||||
}
|
||||
|
||||
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
|
||||
options := &PinLsSettings{
|
||||
Type: "all",
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
err := opt(options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return options, nil
|
||||
}
|
||||
|
||||
type PinOptions struct{}
|
||||
|
||||
func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption {
|
||||
return func(settings *PinAddSettings) error {
|
||||
settings.Recursive = recucsive
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (api *PinOptions) WithType(t string) PinLsOption {
|
||||
return func(settings *PinLsSettings) error {
|
||||
settings.Type = t
|
||||
return nil
|
||||
}
|
||||
}
|
34
core/coreapi/pin.go
Normal file
34
core/coreapi/pin.go
Normal file
@ -0,0 +1,34 @@
|
||||
package coreapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type PinAPI struct {
|
||||
*CoreAPI
|
||||
*caopts.PinOptions
|
||||
}
|
||||
|
||||
func (api *PinAPI) Add(context.Context, coreiface.Path, ...caopts.PinAddOption) error {
|
||||
return errors.New("TODO")
|
||||
}
|
||||
|
||||
func (api *PinAPI) Ls(context.Context) ([]coreiface.Pin, error) {
|
||||
return nil, errors.New("TODO")
|
||||
}
|
||||
|
||||
func (api *PinAPI) Rm(context.Context, coreiface.Path) error {
|
||||
return errors.New("TODO")
|
||||
}
|
||||
|
||||
func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface.Path) error {
|
||||
return errors.New("TODO")
|
||||
}
|
||||
|
||||
func (api *PinAPI) Verify(context.Context) error {
|
||||
return errors.New("TODO")
|
||||
}
|
Reference in New Issue
Block a user