Refactor download creation
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/tardisx/gropple/config"
|
||||
@@ -38,6 +39,8 @@ type Downloads []*Download
|
||||
|
||||
var CanStopDownload = false
|
||||
|
||||
var downloadId int32 = 0
|
||||
|
||||
// StartQueued starts any downloads that have been queued, we would not exceed
|
||||
// maxRunning. If maxRunning is 0, there is no limit.
|
||||
func (dls Downloads) StartQueued(maxRunning int) {
|
||||
@@ -100,6 +103,23 @@ func (dl *Download) Queue() {
|
||||
|
||||
}
|
||||
|
||||
func NewDownload(conf *config.Config, url string) *Download {
|
||||
atomic.AddInt32(&downloadId, 1)
|
||||
dl := Download{
|
||||
Config: conf,
|
||||
|
||||
Id: int(downloadId),
|
||||
Url: url,
|
||||
PopupUrl: fmt.Sprintf("/fetch/%d", int(downloadId)),
|
||||
State: "choose profile",
|
||||
Finished: false,
|
||||
Eta: "?",
|
||||
Percent: 0.0,
|
||||
Log: make([]string, 0, 1000),
|
||||
}
|
||||
return &dl
|
||||
}
|
||||
|
||||
func (dl *Download) Stop() {
|
||||
if !CanStopDownload {
|
||||
log.Print("attempted to stop download on a platform that it is not currently supported on - please report this as a bug")
|
||||
|
||||
Reference in New Issue
Block a user