Skip to content

Commit

Permalink
Force update pin by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 13, 2024
1 parent 396f998 commit b8fe1c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/rootcid.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Takes an IPFS path name and returns the root CID.
// The cached field tells the function whether to use the cached value or not.
func RootCID(name string, cached bool) (cid.Cid, error) {
func ResolveRootCID(name string, cached bool) (cid.Cid, error) {

api := GetIPFSAPI()

Expand Down
13 changes: 1 addition & 12 deletions did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,7 @@ func (d *DID) IsIdenticalTo(did DID) bool {

func (d *DID) Path() (path.Path, error) {

return path.NewPath("/" + path.IPNSNamespace + "/" + d.Id)
}

func (d *DID) ImmutablePath() (path.ImmutablePath, error) {

p, err := d.Path()
if err != nil {
return path.ImmutablePath{}, err
}

return path.NewImmutablePath(p)

return path.NewPath("/" + path.IPNSNamespace + "/" + d.Identifier)
}

func (d *DID) Verify() error {
Expand Down
7 changes: 5 additions & 2 deletions did/doc/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ func FetchFromDID(d did.DID, cached bool) (*Document, cid.Cid, error) {
var document = &Document{}

ipfsAPI := api.GetIPFSAPI()
ip, err := d.ImmutablePath()
ip, err := d.Path()
if err != nil {
return nil, cid.Cid{}, fmt.Errorf("fetchFromDID: %w", err)
}

c := ip.RootCid()
c, err := api.ResolveRootCID(ip.String(), cached)
if err != nil {
return nil, cid.Cid{}, fmt.Errorf("fetchFromDID: %w", err)
}

log.Debugf("Fetching CID: %s", c)

Expand Down
33 changes: 17 additions & 16 deletions did/doc/publication.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func DefaultPublishOptions() *PublishOptions {
return &PublishOptions{
Ctx: context.Background(),
Pin: true,
Force: false,
Force: true,
AllowBigBlock: false,
}
}
Expand All @@ -34,24 +34,25 @@ func DefaultPublishOptions() *PublishOptions {
// If the opts is nil, the default options are used.
// NB! Publication is more than simply adding the document to IPFS.
// It's about publishing the document to IPNS and possibly pinning it.
func (d *Document) Publish(opts *PublishOptions) (ipns.Name, error) {
func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error) {

if opts == nil {
opts = DefaultPublishOptions()
}

if opts.Force {
log.Debugf("DocPublish: force flag is set")
}

if opts.Pin {
log.Debugf("DocPublish: pin flag is set")
}
opts := DefaultPublishOptions()

if opts.AllowBigBlock {
log.Debugf("DocPublish: allow big block flag is set")
// Iterate through all options provided
for _, opt := range o {
if opt == nil {
continue // Skip any nil options
}
if opt.Force {
opts.Force = opt.Force
}
if opt.Pin {
opts.Pin = opt.Pin
}
if opt.AllowBigBlock {
opts.AllowBigBlock = opt.AllowBigBlock
}
}

_did, err := did.New(d.ID)
if err != nil {
return ipns.Name{}, fmt.Errorf("DocPublish: %w", err)
Expand Down

0 comments on commit b8fe1c3

Please sign in to comment.