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

19
main.go
View File

@@ -320,26 +320,13 @@ func fetchHandler(w http.ResponseWriter, r *http.Request) {
// check the URL for a sudden but inevitable betrayal
if strings.Contains(url[0], conf.Server.Address) {
w.WriteHeader(400)
fmt.Fprint(w, "you musn't gropple your gropple :-)")
fmt.Fprint(w, "you mustn't gropple your gropple :-)")
return
}
// create the record
// XXX should be atomic!
downloadId++
newDownload := download.Download{
Config: conf,
Id: downloadId,
Url: url[0],
PopupUrl: fmt.Sprintf("/fetch/%d", downloadId),
State: "choose profile",
Finished: false,
Eta: "?",
Percent: 0.0,
Log: make([]string, 0, 1000),
}
downloads = append(downloads, &newDownload)
newDownload := download.NewDownload(conf, url[0])
downloads = append(downloads, newDownload)
// XXX atomic ^^
newDownload.Log = append(newDownload.Log, "start of log...")