Refactor web #26

Merged
tardisx merged 8 commits from refactor-web into main 2023-11-20 07:38:17 +10:30
Showing only changes of commit 063b28dd7c - Show all commits

View File

@ -212,8 +212,6 @@ func fetchInfoOneRESTHandler(cs *config.ConfigService, dm *download.Manager) fun
type updateRequest struct { type updateRequest struct {
Action string `json:"action"` Action string `json:"action"`
Profile string `json:"profile"`
Destination string `json:"destination"`
} }
thisReq := updateRequest{} thisReq := updateRequest{}
@ -235,46 +233,6 @@ func fetchInfoOneRESTHandler(cs *config.ConfigService, dm *download.Manager) fun
return return
} }
if thisReq.Action == "start" {
// find the profile they asked for
profile := cs.Config.ProfileCalled(thisReq.Profile)
if profile == nil {
panic("bad profile name?")
}
// set the profile
thisDownload.Lock.Lock()
thisDownload.DownloadProfile = *profile
thisDownload.Lock.Unlock()
dm.Queue(thisDownload)
succRes := successResponse{Success: true, Message: "download started"}
succResB, _ := json.Marshal(succRes)
_, err = w.Write(succResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
if thisReq.Action == "change_destination" {
// nil means (probably) that they chose "don't move" - which is fine,
// and maps to nil on the Download (the default state).
destination := cs.Config.DestinationCalled(thisReq.Destination)
dm.ChangeDestination(thisDownload, destination)
// log.Printf("%#v", thisDownload)
succRes := successResponse{Success: true, Message: "destination changed"}
succResB, _ := json.Marshal(succRes)
_, err = w.Write(succResB)
if err != nil {
log.Printf("could not write to client: %s", err)
}
return
}
if thisReq.Action == "stop" { if thisReq.Action == "stop" {
thisDownload.Stop() thisDownload.Stop()
@ -421,7 +379,6 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
Success: true, Success: true,
Location: fmt.Sprintf("/fetch/%d", id), Location: fmt.Sprintf("/fetch/%d", id),
}) })
} }
} else { } else {
// a GET, show the popup so they can start the download (or just close // a GET, show the popup so they can start the download (or just close