Browse Source

further simplifying

pull/294/head
stefanbenten 4 years ago
parent
commit
bd1ebe5186
4 changed files with 70 additions and 68 deletions
  1. +1
    -1
      README.md
  2. +4
    -20
      cmd/cmd.go
  3. +48
    -47
      server/server.go
  4. +17
    -0
      server/utils/template.go

+ 1
- 1
README.md View File

@@ -105,7 +105,7 @@ basedir | path storage for local/gdrive provider| |
cleanup-interval | interval to clean up expired files from local storage | 1 | cleanup-interval | interval to clean up expired files from local storage | 1 |
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| | gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| | gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |
gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | |
gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory | 16 |
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | |
log | path to log file| | log | path to log file| |




+ 4
- 20
cmd/cmd.go View File

@@ -11,25 +11,9 @@ import (
"github.com/dutchcoders/transfer.sh/server/utils" "github.com/dutchcoders/transfer.sh/server/utils"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/urfave/cli" "github.com/urfave/cli"
"google.golang.org/api/googleapi"
) )


var Version = "1.1.4"
var helpTemplate = `NAME:
{{.Name}} - {{.Usage}}

DESCRIPTION:
{{.Description}}

USAGE:
{{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...]

COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}`
const Version = "1.1.4"


var globalFlags = []cli.Flag{ var globalFlags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
@@ -150,8 +134,8 @@ var globalFlags = []cli.Flag{
}, },
cli.IntFlag{ cli.IntFlag{
Name: "gdrive-chunk-size", Name: "gdrive-chunk-size",
Usage: "",
Value: googleapi.DefaultUploadChunkSize / 1024 / 1024,
Usage: "chunk size for gdrive upload in megabytes, must be lower than available memory",
Value: 16,
}, },
cli.IntFlag{ cli.IntFlag{
Name: "rate-limit", Name: "rate-limit",
@@ -236,7 +220,7 @@ func New() *Cmd {
app.Description = `Easy file sharing from the command line` app.Description = `Easy file sharing from the command line`
app.Version = Version app.Version = Version
app.Flags = globalFlags app.Flags = globalFlags
app.CustomAppHelpTemplate = helpTemplate
app.CustomAppHelpTemplate = utils.HelpTemplate
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {
Name: "version", Name: "version",


+ 48
- 47
server/server.go View File

@@ -59,6 +59,50 @@ const _24K = (1 << 3) * 24
// parse request with maximum memory of _5Megabytes // parse request with maximum memory of _5Megabytes
const _5M = (1 << 20) * 5 const _5M = (1 << 20) * 5



type Server struct {
AuthUser string
AuthPass string

logger *log.Logger

tlsConfig *tls.Config

profilerEnabled bool

locks map[string]*sync.Mutex

rateLimitRequests int

storage storage.Storage

lifetime time.Duration

forceHTTPs bool

ipFilterOptions *utils.IPFilterOptions

VirusTotalKey string
ClamAVDaemonHost string

tempPath string

webPath string
proxyPath string
gaKey string
userVoiceKey string

TLSListenerOnly bool

ListenerString string
TLSListenerString string
ProfileListenerString string

Certificate string

LetsEncryptCache string
}

type OptionFn func(*Server) type OptionFn func(*Server)


func ClamavHost(s string) OptionFn { func ClamavHost(s string) OptionFn {
@@ -244,49 +288,6 @@ func FilterOptions(options utils.IPFilterOptions) OptionFn {
} }
} }


type Server struct {
AuthUser string
AuthPass string

logger *log.Logger

tlsConfig *tls.Config

profilerEnabled bool

locks map[string]*sync.Mutex

rateLimitRequests int

storage storage.Storage

lifetime time.Duration

forceHTTPs bool

ipFilterOptions *utils.IPFilterOptions

VirusTotalKey string
ClamAVDaemonHost string

tempPath string

webPath string
proxyPath string
gaKey string
userVoiceKey string

TLSListenerOnly bool

ListenerString string
TLSListenerString string
ProfileListenerString string

Certificate string

LetsEncryptCache string
}

func New(options ...OptionFn) (*Server, error) { func New(options ...OptionFn) (*Server, error) {
s := &Server{ s := &Server{
locks: map[string]*sync.Mutex{}, locks: map[string]*sync.Mutex{},
@@ -299,10 +300,6 @@ func New(options ...OptionFn) (*Server, error) {
return s, nil return s, nil
} }


func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

func (s *Server) Run() { func (s *Server) Run() {
listening := false listening := false


@@ -477,3 +474,7 @@ func (s *Server) Run() {
func stripPrefix(path string) string { func stripPrefix(path string) string {
return strings.Replace(path, web.Prefix+"/", "", -1) return strings.Replace(path, web.Prefix+"/", "", -1)
} }

func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

+ 17
- 0
server/utils/template.go View File

@@ -0,0 +1,17 @@
package utils

const HelpTemplate = `NAME:
{{.Name}} - {{.Usage}}

DESCRIPTION:
{{.Description}}

USAGE:
{{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...]

COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}`

Loading…
Cancel
Save