mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +08:00
Merge pull request #2677 from ipfs/feature/add-default-to-publish
Added Default logic to publish
This commit is contained in:
@ -50,12 +50,12 @@ Publish an <ipfs-path> to another public key (not implemented):
|
|||||||
cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published.").EnableStdin(),
|
cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published.").EnableStdin(),
|
||||||
},
|
},
|
||||||
Options: []cmds.Option{
|
Options: []cmds.Option{
|
||||||
cmds.BoolOption("resolve", "Resolve given path before publishing (default=true)."),
|
cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true),
|
||||||
cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for. Default: 24h.
|
cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for.
|
||||||
|
|
||||||
This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are
|
This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are
|
||||||
"ns", "us" (or "µs"), "ms", "s", "m", "h".
|
"ns", "us" (or "µs"), "ms", "s", "m", "h".
|
||||||
`),
|
`).Default("24h"),
|
||||||
cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
|
cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
|
||||||
},
|
},
|
||||||
Run: func(req cmds.Request, res cmds.Response) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
@ -86,25 +86,18 @@ Publish an <ipfs-path> to another public key (not implemented):
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
popts := &publishOpts{
|
popts := new(publishOpts)
|
||||||
verifyExists: true,
|
|
||||||
pubValidTime: time.Hour * 24,
|
popts.verifyExists, _, _ = req.Option("resolve").Bool()
|
||||||
|
|
||||||
|
validtime, _, _ := req.Option("lifetime").String()
|
||||||
|
d, err := time.ParseDuration(validtime)
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmds.ErrNormal)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
verif, found, _ := req.Option("resolve").Bool()
|
popts.pubValidTime = d
|
||||||
if found {
|
|
||||||
popts.verifyExists = verif
|
|
||||||
}
|
|
||||||
validtime, found, _ := req.Option("lifetime").String()
|
|
||||||
if found {
|
|
||||||
d, err := time.ParseDuration(validtime)
|
|
||||||
if err != nil {
|
|
||||||
res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmds.ErrNormal)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
popts.pubValidTime = d
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
if ttl, found, _ := req.Option("ttl").String(); found {
|
if ttl, found, _ := req.Option("ttl").String(); found {
|
||||||
|
Reference in New Issue
Block a user