From d0163ae2740f4b17f5f472d977d3f2fc184715cd Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Wed, 23 Jul 2025 10:04:06 +0200 Subject: [PATCH] Revert "Fix some errors in Readme.md and some performance optimization (#646)" This reverts commit db3f86235f424079f2a5e0df8c8d2a793a997dfc. --- README.md | 8 ++++---- server/server.go | 10 +++++----- server/token.go | 12 +++--------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8a11a3c..07b6c14 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $ curl -v --upload-file ./hello.txt https://transfer.sh/hello.txt ### Encrypt & Upload: ```bash $ gpg --armor --symmetric --output - /tmp/hello.txt | curl --upload-file - https://transfer.sh/test.txt -``` +```` ### Download & Decrypt: ```bash @@ -56,13 +56,13 @@ $ curl --upload-file ./hello.txt https://transfer.sh/hello.txt -H "Max-Days: 1" ### X-Encrypt-Password #### Beware, use this feature only on your self-hosted server: trusting a third-party service for server side encryption is at your own risk ```bash -$ curl --upload-file ./hello.txt https://your-transfersh-instance.tld/hello.txt -H "X-Encrypt-Password: test" # Encrypt the content server side with AES256 using "test" as password +$ curl --upload-file ./hello.txt https://your-transfersh-instance.tld/hello.txt -H "X-Encrypt-Password: test" # Encrypt the content sever side with AES265 using "test" as password ``` ### X-Decrypt-Password #### Beware, use this feature only on your self-hosted server: trusting a third-party service for server side encryption is at your own risk ```bash -$ curl https://your-transfersh-instance.tld/BAYh0/hello.txt -H "X-Decrypt-Password: test" # Decrypt the content server side with AES256 using "test" as password +$ curl https://your-transfersh-instance.tld/BAYh0/hello.txt -H "X-Decrypt-Password: test" # Decrypt the content sever side with AES265 using "test" as password ``` ## Response Headers @@ -128,7 +128,7 @@ basedir | path storage for local/gdrive provider gdrive-client-json-filepath | path to oauth client json config for gdrive provider | | GDRIVE_CLIENT_JSON_FILEPATH | gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider | | GDRIVE_LOCAL_CONFIG_PATH | gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | | GDRIVE_CHUNK_SIZE | -lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma separated) | | HOSTS | +lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | HOSTS | log | path to log file | | LOG | cors-domains | comma separated list of domains for CORS, setting it enable CORS | | CORS_DOMAINS | clamav-host | host for clamav feature | | CLAMAV_HOST | diff --git a/server/server.go b/server/server.go index 7991384..b7a4e92 100644 --- a/server/server.go +++ b/server/server.go @@ -144,7 +144,7 @@ func ProfileListener(s string) OptionFn { func WebPath(s string) OptionFn { return func(srvr *Server) { if s[len(s)-1:] != "/" { - s = filepath.Join(s, "") + s = s + string(filepath.Separator) } srvr.webPath = s @@ -155,7 +155,7 @@ func WebPath(s string) OptionFn { func ProxyPath(s string) OptionFn { return func(srvr *Server) { if s[len(s)-1:] != "/" { - s = filepath.Join(s, "") + s = s + string(filepath.Separator) } srvr.proxyPath = s @@ -173,7 +173,7 @@ func ProxyPort(s string) OptionFn { func TempPath(s string) OptionFn { return func(srvr *Server) { if s[len(s)-1:] != "/" { - s = filepath.Join(s, "") + s = s + string(filepath.Separator) } srvr.tempPath = s @@ -436,8 +436,8 @@ func (s *Server) Run() { fs = http.Dir(s.webPath) - htmlTemplates, _ = htmlTemplates.ParseGlob(filepath.Join(s.webPath, "*.html")) - textTemplates, _ = textTemplates.ParseGlob(filepath.Join(s.webPath, "*.txt")) + htmlTemplates, _ = htmlTemplates.ParseGlob(s.webPath + "*.html") + textTemplates, _ = textTemplates.ParseGlob(s.webPath + "*.txt") } else { fs = &assetfs.AssetFS{ Asset: web.Asset, diff --git a/server/token.go b/server/token.go index 4647ec7..d73403e 100644 --- a/server/token.go +++ b/server/token.go @@ -24,10 +24,6 @@ THE SOFTWARE. package server -import ( - "strings" -) - const ( // SYMBOLS characters used for short-urls SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -35,13 +31,11 @@ const ( // generate a token func token(length int) string { - var builder strings.Builder - builder.Grow(length) - + result := "" for i := 0; i < length; i++ { x := theRand.Intn(len(SYMBOLS) - 1) - builder.WriteByte(SYMBOLS[x]) + result = string(SYMBOLS[x]) + result } - return builder.String() + return result }