Quellcode durchsuchen

Remove chunk size setting

Conforms with the PHP backend behavior
Maddie Zhan vor 5 Jahren
Ursprung
Commit
96ea2ede4c
5 geänderte Dateien mit 14 neuen und 18 gelöschten Zeilen
  1. 0 2
      README.md
  2. 3 4
      config/config.go
  3. 0 4
      main.go
  4. 0 2
      settings.toml
  5. 11 6
      web/web.go

+ 0 - 2
README.md

@@ -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=""
     

+ 3 - 4
config/config.go

@@ -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"`

+ 0 - 4
main.go

@@ -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))
 }

+ 0 - 2
settings.toml

@@ -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=""
 

+ 11 - 6
web/web.go

@@ -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)
+			}
 		}
 	}