Compare commits
4 Commits
6434d0d5d3
...
4c477c5b9f
Author | SHA1 | Date |
---|---|---|
Alexey Kostin | 4c477c5b9f | |
Alexey Kostin | 1eecc22fb3 | |
Alexey Kostin | 27c38e6a1e | |
Alexey Kostin | ca5c89f130 |
3
go.mod
3
go.mod
|
@ -16,6 +16,7 @@ require (
|
|||
github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329
|
||||
github.com/dutchcoders/transfer.sh-web v0.0.0-20221119114740-ca3a2621d2a6
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
||||
github.com/emicklei/go-restful v2.16.0+incompatible
|
||||
github.com/fatih/color v1.14.1
|
||||
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f
|
||||
github.com/gorilla/handlers v1.5.1
|
||||
|
@ -29,6 +30,7 @@ require (
|
|||
golang.org/x/crypto v0.17.0
|
||||
golang.org/x/net v0.17.0
|
||||
golang.org/x/oauth2 v0.7.0
|
||||
golang.org/x/text v0.14.0
|
||||
google.golang.org/api v0.114.0
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
|
||||
storj.io/common v0.0.0-20230301105927-7f966760c100
|
||||
|
@ -86,7 +88,6 @@ require (
|
|||
go.opencensus.io v0.24.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
|
||||
google.golang.org/grpc v1.56.3 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -85,6 +85,8 @@ github.com/dutchcoders/transfer.sh-web v0.0.0-20221119114740-ca3a2621d2a6 h1:7uT
|
|||
github.com/dutchcoders/transfer.sh-web v0.0.0-20221119114740-ca3a2621d2a6/go.mod h1:F6Q37CxDh2MHr5KXkcZmNB3tdkK7v+bgE+OpBY+9ilI=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/emicklei/go-restful v2.16.0+incompatible h1:rgqiKNjTnFQA6kkhFe16D8epTksy9HQ1MyrbDXSdYhM=
|
||||
github.com/emicklei/go-restful v2.16.0+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
|
|
|
@ -51,6 +51,7 @@ import (
|
|||
"sync"
|
||||
textTemplate "text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/ProtonMail/go-crypto/openpgp"
|
||||
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
||||
|
@ -66,6 +67,9 @@ import (
|
|||
blackfriday "github.com/russross/blackfriday/v2"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
"golang.org/x/net/idna"
|
||||
"golang.org/x/text/runes"
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
const getPathPart = "get"
|
||||
|
@ -418,7 +422,24 @@ func (s *Server) notFoundHandler(w http.ResponseWriter, _ *http.Request) {
|
|||
}
|
||||
|
||||
func sanitize(fileName string) string {
|
||||
return path.Base(fileName)
|
||||
t := transform.Chain(
|
||||
norm.NFD,
|
||||
runes.Remove(runes.In(unicode.Cc)),
|
||||
runes.Remove(runes.In(unicode.Cf)),
|
||||
runes.Remove(runes.In(unicode.Co)),
|
||||
runes.Remove(runes.In(unicode.Cs)),
|
||||
runes.Remove(runes.In(unicode.Other)),
|
||||
runes.Remove(runes.In(unicode.Zl)),
|
||||
runes.Remove(runes.In(unicode.Zp)),
|
||||
norm.NFC)
|
||||
newName, _, err := transform.String(t, fileName)
|
||||
if err != nil {
|
||||
return path.Base(fileName)
|
||||
}
|
||||
if len(newName) == 0 {
|
||||
newName = "_"
|
||||
}
|
||||
return path.Base(newName)
|
||||
}
|
||||
|
||||
func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -25,7 +25,9 @@ THE SOFTWARE.
|
|||
package server
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
"log"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -35,11 +37,14 @@ const (
|
|||
|
||||
// generate a token
|
||||
func token(length int) string {
|
||||
result := ""
|
||||
result := make([]byte, length)
|
||||
for i := 0; i < length; i++ {
|
||||
x := rand.Intn(len(SYMBOLS) - 1)
|
||||
result = string(SYMBOLS[x]) + result
|
||||
x, err := rand.Int(rand.Reader, big.NewInt(int64(len(SYMBOLS))))
|
||||
if err != nil {
|
||||
log.Fatal("Failed to generate token")
|
||||
}
|
||||
result[i] = SYMBOLS[x.Int64()]
|
||||
}
|
||||
|
||||
return result
|
||||
return string(result)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue