Remove chunk size setting

Conforms with the PHP backend behavior
This commit is contained in:
Maddie Zhan 2020-03-19 11:02:23 +08:00
parent 62b8a3c17f
commit 96ea2ede4c
5 changed files with 14 additions and 18 deletions

View file

@ -68,8 +68,6 @@ You need Go 1.13+ to compile the binary.
bind_address="127.0.0.1"
# backend listen port, default is 8989
listen_port=8989
# download test chunks, default is 4
download_chunks=4
# ipinfo.io API key, if applicable
ipinfo_api_key=""

View file

@ -6,10 +6,9 @@ import (
)
type Config struct {
BindAddress string `mapstructure:"bind_address"`
Port string `mapstructure:"listen_port"`
DownloadChunks int `mapstructure:"download_chunks"`
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
BindAddress string `mapstructure:"bind_address"`
Port string `mapstructure:"listen_port"`
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
StatsPassword string `mapstructure:"statistics_password"`
RedactIP bool `mapstructure:"redact_ip_addresses"`

View file

@ -11,10 +11,6 @@ import (
func main() {
conf := config.Load()
if conf.DownloadChunks > 1024 {
log.Fatal("chunks can't be more than 1024")
}
database.SetDBInfo(&conf)
log.Fatal(web.ListenAndServe(&conf))
}

View file

@ -2,8 +2,6 @@
bind_address=""
# backend listen port
listen_port=8989
# download test chunks
download_chunks=4
# ipinfo.io API key, if applicable
ipinfo_api_key=""

View file

@ -91,17 +91,22 @@ func garbage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename=random.dat")
w.Header().Set("Content-Transfer-Encoding", "binary")
conf := config.LoadedConfig()
ckSize := r.FormValue("ckSize")
// chunk size set to 4 by default
chunks := 4
chunks := conf.DownloadChunks
ckSize := r.FormValue("ckSize")
if ckSize != "" {
i, err := strconv.ParseInt(ckSize, 10, 64)
if err == nil && i > 0 && i < 1024 {
chunks = int(i)
} else {
if err != nil {
log.Errorf("Invalid chunk size: %s", ckSize)
log.Warn("Will use default value %d", chunks)
} else {
// limit max chunk size to 1024
if i > 1024 {
chunks = 1024
} else {
chunks = int(i)
}
}
}