mc share output cleanup
This commit is contained in:
+27
-9
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/cli"
|
||||
@@ -75,7 +76,7 @@ type ShareMessage ShareMessageV3
|
||||
// String - regular colorized message
|
||||
func (s ShareMessage) String() string {
|
||||
if len(s.DownloadURL) > 0 {
|
||||
return console.Colorize("Share", fmt.Sprintf("Expiry: %s\n DownloadURL: %s\n Key: %s", timeDurationToHumanizedTime(s.Expiry), s.DownloadURL, s.Key))
|
||||
return console.Colorize("Share", fmt.Sprintf("%s", s.DownloadURL))
|
||||
}
|
||||
var key string
|
||||
URL := client.NewURL(s.Key)
|
||||
@@ -88,8 +89,10 @@ func (s ShareMessage) String() string {
|
||||
}
|
||||
curlCommand = curlCommand + fmt.Sprintf("-F %s=%s ", k, v)
|
||||
}
|
||||
curlCommand = curlCommand + fmt.Sprintf("-F key=%s ", key) + "-F file=@<LOCALFILEPATH> "
|
||||
return console.Colorize("Share", fmt.Sprintf("Expiry: %s\n curl-command: %s\n Key: %s", timeDurationToHumanizedTime(s.Expiry), curlCommand, s.Key))
|
||||
curlCommand = curlCommand + fmt.Sprintf("-F key=%s ", key) + "-F file=@<FILE> "
|
||||
emphasize := console.Colorize("File", "<FILE>")
|
||||
curlCommand = strings.Replace(curlCommand, "<FILE>", emphasize, -1)
|
||||
return console.Colorize("Share", fmt.Sprintf("%s", curlCommand))
|
||||
}
|
||||
|
||||
// JSON json message for share command
|
||||
@@ -107,14 +110,27 @@ func (s ShareMessage) JSON() string {
|
||||
Key: s.Key,
|
||||
})
|
||||
} else {
|
||||
var key string
|
||||
URL := client.NewURL(s.Key)
|
||||
postURL := URL.Scheme + URL.SchemeSeparator + URL.Host + string(URL.Separator) + s.UploadInfo["bucket"] + " "
|
||||
curlCommand := "curl " + postURL
|
||||
for k, v := range s.UploadInfo {
|
||||
if k == "key" {
|
||||
key = v
|
||||
continue
|
||||
}
|
||||
curlCommand = curlCommand + fmt.Sprintf("-F %s=%s ", k, v)
|
||||
}
|
||||
curlCommand = curlCommand + fmt.Sprintf("-F key=%s ", key) + "-F file=@<FILE> "
|
||||
|
||||
shareMessageBytes, err = json.Marshal(struct {
|
||||
Expiry humanizedTime `json:"expiry"`
|
||||
UploadInfo map[string]string `json:"uploadInfo"`
|
||||
Key string `json:"keyName"`
|
||||
Expiry humanizedTime `json:"expiry"`
|
||||
UploadCommand string `json:"uploadCommand"`
|
||||
Key string `json:"keyName"`
|
||||
}{
|
||||
Expiry: timeDurationToHumanizedTime(s.Expiry),
|
||||
UploadInfo: s.UploadInfo,
|
||||
Key: s.Key,
|
||||
Expiry: timeDurationToHumanizedTime(s.Expiry),
|
||||
UploadCommand: curlCommand,
|
||||
Key: s.Key,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -123,6 +139,8 @@ func (s ShareMessage) JSON() string {
|
||||
// json encoding escapes ampersand into its unicode character which is not usable directly for share
|
||||
// and fails with cloud storage. convert them back so that they are usable
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u003c"), []byte("<"), -1)
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u003e"), []byte(">"), -1)
|
||||
return string(shareMessageBytes)
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -17,6 +17,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/cli"
|
||||
@@ -64,9 +66,14 @@ func mainShareUpload(ctx *cli.Context) {
|
||||
var err error
|
||||
shareDataDirSetup()
|
||||
checkShareUploadSyntax(ctx)
|
||||
setSharePalette(ctx.GlobalString("colors"))
|
||||
|
||||
args := ctx.Args()
|
||||
config := mustGetMcConfig()
|
||||
url := args.Get(0)
|
||||
if strings.HasSuffix(url, "/") {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Upload location can not end with '/'. Did you mean %s%s", url, recursiveSeparator))
|
||||
}
|
||||
if len(args.Get(1)) == 0 {
|
||||
expires = time.Duration(604800) * time.Second
|
||||
} else {
|
||||
@@ -78,8 +85,6 @@ func mainShareUpload(ctx *cli.Context) {
|
||||
contentType := args.Get(2)
|
||||
targetURL := getAliasURL(url, config.Aliases)
|
||||
|
||||
setSharePalette(ctx.GlobalString("colors"))
|
||||
|
||||
e := doShareUploadURL(stripRecursiveURL(targetURL), isURLRecursive(targetURL), expires, contentType)
|
||||
fatalIf(e.Trace(targetURL), "Unable to generate URL for sharing.")
|
||||
}
|
||||
@@ -103,7 +108,7 @@ func doShareUploadURL(targetURL string, recursive bool, expires time.Duration, c
|
||||
Key := targetURL
|
||||
if recursive {
|
||||
Key = Key + recursiveSeparator
|
||||
m["key"] = "<KEY>"
|
||||
m["key"] = m["key"] + "<FILE>"
|
||||
}
|
||||
shareMessage := ShareMessage{
|
||||
Expiry: expires,
|
||||
|
||||
@@ -222,12 +222,14 @@ func setSharePalette(style string) {
|
||||
"Share": color.New(color.FgGreen, color.Bold),
|
||||
"Expires": color.New(color.FgRed, color.Bold),
|
||||
"URL": color.New(color.FgCyan, color.Bold),
|
||||
"File": color.New(color.FgRed, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Share": color.New(color.FgWhite, color.Bold),
|
||||
"Expires": color.New(color.FgWhite, color.Bold),
|
||||
"URL": color.New(color.FgWhite, color.Bold),
|
||||
"File": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user