Refactor download creation

This commit is contained in:
2022-04-06 20:35:28 +09:30
parent bdf9730ab0
commit c05bed1148
2 changed files with 23 additions and 16 deletions

View File

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