ytsync/sources/shared.go

28 lines
665 B
Go
Raw Normal View History

2018-02-13 18:47:05 +01:00
package sources
import (
"strings"
2018-02-13 18:47:05 +01:00
"github.com/lbryio/lbry.go/jsonrpc"
2018-09-18 21:20:34 +02:00
"github.com/lbryio/lbry.go/ytsync"
2018-02-13 18:47:05 +01:00
)
type SyncSummary struct {
ClaimID string
ClaimName string
}
2018-09-18 21:20:34 +02:00
func publishAndRetryExistingNames(daemon *jsonrpc.Client, title, filename string, amount float64, options jsonrpc.PublishOptions, namer *ytsync.Namer) (*SyncSummary, error) {
2018-02-13 18:47:05 +01:00
for {
2018-09-18 21:20:34 +02:00
name := namer.GetNextName(title)
response, err := daemon.Publish(name, filename, amount, options)
2018-09-18 21:20:34 +02:00
if err != nil {
if strings.Contains(err.Error(), "failed: Multiple claims (") {
2018-02-13 18:47:05 +01:00
continue
}
return nil, err
2018-02-13 18:47:05 +01:00
}
2018-09-18 21:20:34 +02:00
return &SyncSummary{ClaimID: response.ClaimID, ClaimName: name}, nil
2018-02-13 18:47:05 +01:00
}
}