Replace shell-based downloader execution with validated arguments, enforce request hardening and safer defaults, and refactor handlers/router/state so job control is safer and easier to maintain.
31 lines
514 B
Go
31 lines
514 B
Go
package main
|
|
|
|
import (
|
|
"net/url"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
type ProgressInfo struct {
|
|
Percentage float64
|
|
CurrentFile string
|
|
Paused bool
|
|
Status string
|
|
}
|
|
|
|
var speedLimitRegex = regexp.MustCompile(`^([1-9]\d*(\.\d+)?)(KBps|MBps|GBps)$`)
|
|
|
|
func withToken(path string) string {
|
|
token := strings.TrimSpace(config.Security.AuthToken)
|
|
if token == "" {
|
|
return path
|
|
}
|
|
|
|
separator := "?"
|
|
if strings.Contains(path, "?") {
|
|
separator = "&"
|
|
}
|
|
|
|
return path + separator + "token=" + url.QueryEscape(token)
|
|
}
|