* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
34 lines
548 B
Go
34 lines
548 B
Go
package dlutil
|
|
|
|
import "time"
|
|
|
|
var threadsLevels = []struct {
|
|
threads int
|
|
size int64
|
|
}{
|
|
{1, 10 << 20},
|
|
{2, 50 << 20},
|
|
{4, 200 << 20},
|
|
{8, 500 << 20},
|
|
}
|
|
|
|
func BestThreads(size int64, max int) int {
|
|
for _, thread := range threadsLevels {
|
|
if size < thread.size {
|
|
return min(thread.threads, max)
|
|
}
|
|
}
|
|
return max
|
|
}
|
|
|
|
func GetSpeed(downloaded int64, startTime time.Time) float64 {
|
|
if startTime.IsZero() {
|
|
return 0
|
|
}
|
|
elapsed := time.Since(startTime).Seconds()
|
|
if elapsed <= 0 {
|
|
return 0
|
|
}
|
|
return float64(downloaded) / elapsed
|
|
}
|