mirror of https://github.com/perkeep/perkeep.git
cmd/camput: print share URL
After successfully issueing a shared blob. Fixes #330 Change-Id: I51d4fa8434e8df471a29922bfdb5e9a7f22aec1a
This commit is contained in:
parent
7291617da7
commit
bfce01e7b2
|
@ -87,7 +87,17 @@ func (c *shareCmd) RunCommand(args []string) error {
|
|||
unsigned.SetShareExpiration(time.Now().Add(c.duration))
|
||||
}
|
||||
|
||||
pr, err := getUploader().UploadAndSignBlob(unsigned)
|
||||
handleResult("share", pr, err)
|
||||
up := getUploader()
|
||||
shareRoot, err := up.ShareRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pr, err := up.UploadAndSignBlob(unsigned)
|
||||
if err := handleResult("share", pr, err); err != nil {
|
||||
// Because handling the failure is left to cmdmain
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(cmdmain.Stdout, "%s%s\n", shareRoot, pr.BlobRef)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ type Client struct {
|
|||
syncHandlers []*SyncInfo // "from" and "to" url prefix for each syncHandler
|
||||
serverKeyID string // Server's GPG public key ID.
|
||||
helpRoot string // Handler prefix, or "" if none
|
||||
shareRoot string // Share handler prefix, or "" if none
|
||||
|
||||
signerOnce sync.Once
|
||||
signer *schema.Signer
|
||||
|
@ -401,6 +402,9 @@ var ErrNoSearchRoot = errors.New("client: server doesn't support search")
|
|||
// ErrNoHelpRoot is returned by HelpRoot if the server doesn't have a help handler.
|
||||
var ErrNoHelpRoot = errors.New("client: server does not have a help handler")
|
||||
|
||||
// ErrNoShareRoot is returned by ShareRoot if the server doesn't have a share handler.
|
||||
var ErrNoShareRoot = errors.New("client: server does not have a share handler")
|
||||
|
||||
// ErrNoSigning is returned by ServerKeyID if the server doesn't support signing.
|
||||
var ErrNoSigning = fmt.Errorf("client: server doesn't support signing")
|
||||
|
||||
|
@ -462,6 +466,19 @@ func (c *Client) HelpRoot() (string, error) {
|
|||
return c.helpRoot, nil
|
||||
}
|
||||
|
||||
// ShareRoot returns the server's share handler prefix URL.
|
||||
// If the server isn't running a share handler, the error will be
|
||||
// ErrNoShareRoot.
|
||||
func (c *Client) ShareRoot() (string, error) {
|
||||
if err := c.condDiscovery(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if c.shareRoot == "" {
|
||||
return "", ErrNoShareRoot
|
||||
}
|
||||
return c.shareRoot, nil
|
||||
}
|
||||
|
||||
// StorageGeneration returns the server's unique ID for its storage
|
||||
// generation, reset whenever storage is reset, moved, or partially
|
||||
// lost.
|
||||
|
@ -820,6 +837,12 @@ func (c *Client) doDiscovery() error {
|
|||
}
|
||||
c.helpRoot = u.String()
|
||||
|
||||
u, err = root.Parse(disco.ShareRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("client: invalid shareRoot %q; failed to resolve", disco.ShareRoot)
|
||||
}
|
||||
c.shareRoot = u.String()
|
||||
|
||||
c.storageGen = disco.StorageGeneration
|
||||
|
||||
u, err = root.Parse(disco.BlobRoot)
|
||||
|
|
Loading…
Reference in New Issue