mirror of
https://github.com/fiatjaf/nak.git
synced 2026-01-25 11:58:53 +00:00
--outbox flag for encode.
This commit is contained in:
55
encode.go
55
encode.go
@@ -25,13 +25,6 @@ var encode = &cli.Command{
|
|||||||
"relays":["wss://nada.zero"],
|
"relays":["wss://nada.zero"],
|
||||||
"author":"ebb6ff85430705651b311ed51328767078fd790b14f02d22efba68d5513376bc"
|
"author":"ebb6ff85430705651b311ed51328767078fd790b14f02d22efba68d5513376bc"
|
||||||
} | nak encode`,
|
} | nak encode`,
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "relay",
|
|
||||||
Aliases: []string{"r"},
|
|
||||||
Usage: "attach relay hints to naddr code",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
DisableSliceFlagSeparator: true,
|
DisableSliceFlagSeparator: true,
|
||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
if c.Args().Len() != 0 {
|
if c.Args().Len() != 0 {
|
||||||
@@ -126,7 +119,12 @@ var encode = &cli.Command{
|
|||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "relay",
|
Name: "relay",
|
||||||
Aliases: []string{"r"},
|
Aliases: []string{"r"},
|
||||||
Usage: "attach relay hints to nprofile code",
|
Usage: "attach relay hints to the code",
|
||||||
|
},
|
||||||
|
&BoolIntFlag{
|
||||||
|
Name: "outbox",
|
||||||
|
Usage: "automatically appends outbox relays to the code",
|
||||||
|
Value: 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DisableSliceFlagSeparator: true,
|
DisableSliceFlagSeparator: true,
|
||||||
@@ -139,6 +137,13 @@ var encode = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
relays := c.StringSlice("relay")
|
relays := c.StringSlice("relay")
|
||||||
|
|
||||||
|
if getBoolInt(c, "outbox") > 0 {
|
||||||
|
for _, r := range sys.FetchOutboxRelays(ctx, pk, int(getBoolInt(c, "outbox"))) {
|
||||||
|
relays = appendUnique(relays, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -159,6 +164,16 @@ var encode = &cli.Command{
|
|||||||
Aliases: []string{"a"},
|
Aliases: []string{"a"},
|
||||||
Usage: "attach an author pubkey as a hint to the nevent code",
|
Usage: "attach an author pubkey as a hint to the nevent code",
|
||||||
},
|
},
|
||||||
|
&cli.StringSliceFlag{
|
||||||
|
Name: "relay",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "attach relay hints to the code",
|
||||||
|
},
|
||||||
|
&BoolIntFlag{
|
||||||
|
Name: "outbox",
|
||||||
|
Usage: "automatically appends outbox relays to the code",
|
||||||
|
Value: 3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
DisableSliceFlagSeparator: true,
|
DisableSliceFlagSeparator: true,
|
||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
@@ -171,6 +186,13 @@ var encode = &cli.Command{
|
|||||||
|
|
||||||
author := getPubKey(c, "author")
|
author := getPubKey(c, "author")
|
||||||
relays := c.StringSlice("relay")
|
relays := c.StringSlice("relay")
|
||||||
|
|
||||||
|
if getBoolInt(c, "outbox") > 0 && author != nostr.ZeroPK {
|
||||||
|
for _, r := range sys.FetchOutboxRelays(ctx, author, int(getBoolInt(c, "outbox"))) {
|
||||||
|
relays = appendUnique(relays, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -204,6 +226,16 @@ var encode = &cli.Command{
|
|||||||
Usage: "kind of referred replaceable event",
|
Usage: "kind of referred replaceable event",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
&cli.StringSliceFlag{
|
||||||
|
Name: "relay",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "attach relay hints to the code",
|
||||||
|
},
|
||||||
|
&BoolIntFlag{
|
||||||
|
Name: "outbox",
|
||||||
|
Usage: "automatically appends outbox relays to the code",
|
||||||
|
Value: 3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
DisableSliceFlagSeparator: true,
|
DisableSliceFlagSeparator: true,
|
||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
@@ -224,6 +256,13 @@ var encode = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
relays := c.StringSlice("relay")
|
relays := c.StringSlice("relay")
|
||||||
|
|
||||||
|
if getBoolInt(c, "outbox") > 0 {
|
||||||
|
for _, r := range sys.FetchOutboxRelays(ctx, pubkey, int(getBoolInt(c, "outbox"))) {
|
||||||
|
relays = appendUnique(relays, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
if err := normalizeAndValidateRelayURLs(relays); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
56
flags.go
56
flags.go
@@ -11,6 +11,62 @@ import (
|
|||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
BoolIntFlag = cli.FlagBase[int, struct{}, boolIntValue]
|
||||||
|
)
|
||||||
|
|
||||||
|
type boolIntValue struct {
|
||||||
|
int int
|
||||||
|
defaultWhenSet int
|
||||||
|
hasDefault bool
|
||||||
|
hasBeenSet bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ cli.ValueCreator[int, struct{}] = boolIntValue{}
|
||||||
|
|
||||||
|
func (t boolIntValue) Create(val int, p *int, c struct{}) cli.Value {
|
||||||
|
*p = val
|
||||||
|
|
||||||
|
return &boolIntValue{
|
||||||
|
defaultWhenSet: val,
|
||||||
|
hasDefault: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t boolIntValue) IsBoolFlag() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t boolIntValue) ToString(b int) string { return "<<>>" }
|
||||||
|
|
||||||
|
func (t *boolIntValue) Set(value string) error {
|
||||||
|
t.hasBeenSet = true
|
||||||
|
if value == "true" {
|
||||||
|
if t.hasDefault {
|
||||||
|
t.int = t.defaultWhenSet
|
||||||
|
} else {
|
||||||
|
t.int = 1
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
t.int, err = strconv.Atoi(value)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *boolIntValue) String() string { return fmt.Sprintf("%#v", t.int) }
|
||||||
|
func (t *boolIntValue) Value() int { return t.int }
|
||||||
|
func (t *boolIntValue) Get() any { return t.int }
|
||||||
|
|
||||||
|
func getBoolInt(cmd *cli.Command, name string) int {
|
||||||
|
return cmd.Value(name).(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
type NaturalTimeFlag = cli.FlagBase[nostr.Timestamp, struct{}, naturalTimeValue]
|
type NaturalTimeFlag = cli.FlagBase[nostr.Timestamp, struct{}, naturalTimeValue]
|
||||||
|
|
||||||
type naturalTimeValue struct {
|
type naturalTimeValue struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user