@@ -42,6 +42,7 @@ func GetCommands() []*cobra.Command {
4242
4343 downloadCmd .Flags ().StringP ("source" , "s" , "" , "" )
4444 downloadCmd .Flags ().StringP ("destination" , "d" , "" , "" )
45+ downloadCmd .Flags ().BoolP ("private" , "p" , true , "" )
4546
4647 return []* cobra.Command {uploadCmd , downloadCmd }
4748}
@@ -95,27 +96,28 @@ func upload(cmd *cobra.Command, args []string) {
9596 destination = enteredDestination
9697 }
9798
99+ destination = strings .TrimRight (destination , "/" ) + "/"
100+
98101 queue := make (chan string , 25 )
99102 uploader := sync.WaitGroup {}
100103 matcher := regexp .MustCompile (".*(jpe?g|png|svg|css|csv|js|txt|doc|eot|json|xls|xlsx|pdf|xml|mp4|mov|zip|md)$" )
101104 uploader .Add (1 )
102105 for i := 0 ; i < runtime .NumCPU (); i ++ {
103- go func () {
106+ go func (group * sync. WaitGroup ) {
104107 for path := range queue {
108+ relativePath , err := filepath .Rel (source , path )
105109
106- trimmedPath := path
107- if idx := strings .LastIndex (trimmedPath , "/" ); idx != - 1 {
108- trimmedPath = trimmedPath [0 : idx + 1 ]
110+ if err != nil {
111+ logging .Log .Errorf ("✗ failed to upload `%s`" , path , err )
109112 }
110113
111- relativePath := strings .TrimLeft (trimmedPath , source )
112- replacer := strings .NewReplacer ("//" , "/" )
113- destinationDir := replacer .Replace (strings .Join ([]string {destination , relativePath }, "/" ))
114+ destinationPath := filepath .Dir (destination + relativePath )
114115
115- signature , err := ac .GetSignature (destinationDir , "upsert" )
116+ uploadAsPrivateFile , _ := cmd .Flags ().GetBool ("private" )
117+ signature , err := ac .GetSignature (destinationPath , "upsert" , uploadAsPrivateFile )
116118 if err != nil {
117- logging .Log .Warnf ("✗ failed to get a signature url for `%s`" , destinationDir )
118- return
119+ logging .Log .Warnf ("✗ failed to get a signature url for `%s`" , filepath . Dir ( destinationPath ) )
120+
119121 }
120122
121123 file , err := ac .Upload (path , filepath .Base (path ), signature )
@@ -124,10 +126,10 @@ func upload(cmd *cobra.Command, args []string) {
124126 } else {
125127 logging .Log .Infof ("✔ Uploaded `%s` on url `%s`" , file .Filename , file .Url )
126128 }
127- uploader .Done ()
129+ group .Done ()
128130 }
129131
130- }()
132+ }(& uploader )
131133 }
132134
133135 err = filepath .Walk (source ,
0 commit comments