mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-17 04:30:57 +01:00
little enhancements, supports dirs
This commit is contained in:
@@ -15,3 +15,5 @@ Simple standalone file upload server with api and cli
|
|||||||
- add auth options (access key, users, roles, oauth2)
|
- add auth options (access key, users, roles, oauth2)
|
||||||
- add metrics
|
- add metrics
|
||||||
- add upctl command to remove a file
|
- add upctl command to remove a file
|
||||||
|
- upd: add short uuid to files, in case multiple files with the same
|
||||||
|
name are being uploaded
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ func Execute() {
|
|||||||
return completion(cmd, ShowCompletion)
|
return completion(cmd, ShowCompletion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
return errors.New("No files specified to upload!")
|
||||||
|
}
|
||||||
|
|
||||||
// errors at this stage do not cause the usage to be shown
|
// errors at this stage do not cause the usage to be shown
|
||||||
cmd.SilenceUsage = true
|
cmd.SilenceUsage = true
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,12 @@ package lib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
//"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/imroc/req/v3"
|
"github.com/imroc/req/v3"
|
||||||
"github.com/tlinden/up/upctl/cfg"
|
"github.com/tlinden/up/upctl/cfg"
|
||||||
//"path/filepath"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,10 +35,6 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Runclient(c *cfg.Config, args []string) error {
|
func Runclient(c *cfg.Config, args []string) error {
|
||||||
if len(args) == 0 {
|
|
||||||
return errors.New("No files specified to upload.")
|
|
||||||
}
|
|
||||||
|
|
||||||
client := req.C()
|
client := req.C()
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
client.DevMode()
|
client.DevMode()
|
||||||
@@ -49,9 +46,33 @@ func Runclient(c *cfg.Config, args []string) error {
|
|||||||
|
|
||||||
rq := client.R()
|
rq := client.R()
|
||||||
for _, file := range args {
|
for _, file := range args {
|
||||||
|
info, err := os.Stat(file)
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
err := filepath.Walk(file, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() {
|
||||||
|
rq.SetFile("upload[]", path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
rq.SetFile("upload[]", file)
|
rq.SetFile("upload[]", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if c.Retries > 0 {
|
if c.Retries > 0 {
|
||||||
// Enable retry and set the maximum retry count.
|
// Enable retry and set the maximum retry count.
|
||||||
rq.SetRetryCount(c.Retries).
|
rq.SetRetryCount(c.Retries).
|
||||||
@@ -73,6 +94,7 @@ func Runclient(c *cfg.Config, args []string) error {
|
|||||||
}).
|
}).
|
||||||
SetUploadCallbackWithInterval(func(info req.UploadInfo) {
|
SetUploadCallbackWithInterval(func(info req.UploadInfo) {
|
||||||
fmt.Printf("\r%q uploaded %.2f%%", info.FileName, float64(info.UploadedSize)/float64(info.FileSize)*100.0)
|
fmt.Printf("\r%q uploaded %.2f%%", info.FileName, float64(info.UploadedSize)/float64(info.FileSize)*100.0)
|
||||||
|
fmt.Println()
|
||||||
}, 10*time.Millisecond).
|
}, 10*time.Millisecond).
|
||||||
Post(url)
|
Post(url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user