Destinations are now DownloadOptions

This commit is contained in:
2023-11-20 21:01:50 +10:30
parent fa978fecc2
commit a1e6421842
12 changed files with 200 additions and 139 deletions

View File

@@ -317,9 +317,9 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
} else if method == "POST" {
// creating a new one
type reqType struct {
URL string `json:"url"`
ProfileChosen string `json:"profile"`
DestinationChosen string `json:"destination"`
URL string `json:"url"`
ProfileChosen string `json:"profile"`
DownloadOptionChosen string `json:"download_option"`
}
req := reqType{}
@@ -356,20 +356,12 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
return
}
destination := cs.Config.DestinationCalled(req.DestinationChosen)
if req.DestinationChosen != "" && destination == nil {
w.WriteHeader(400)
json.NewEncoder(w).Encode(errorResponse{
Success: false,
Error: fmt.Sprintf("no such destination: '%s'", req.DestinationChosen),
})
return
}
option := cs.Config.DownloadOptionCalled(req.DownloadOptionChosen)
// create the new download
newDL := download.NewDownload(req.URL, cs.Config)
id := newDL.Id
newDL.Destination = destination
newDL.DownloadOption = option
newDL.DownloadProfile = *profile
dm.AddDownload(newDL)
dm.Queue(newDL)