Start of support for not starting the download immediately
This commit is contained in:
parent
ac286ec24e
commit
1be673d28b
60
web/data/templates/popup_create.tmpl
Normal file
60
web/data/templates/popup_create.tmpl
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
{{ define "content" }}
|
||||||
|
<div id="layout" class="pure-g pure-u-1" x-data="popup_create()" x-init="">
|
||||||
|
<h2>Download create</h2>
|
||||||
|
<p>URL: <tt>{{ .url }}</tt></p>
|
||||||
|
<table class="pure-table" >
|
||||||
|
<tr>
|
||||||
|
<th>profile</th>
|
||||||
|
<td>
|
||||||
|
<select x-bind:disabled="profile_chosen" x-on:change="update_profile()" class="pure-input-1-2" x-model="profile_chosen">
|
||||||
|
<option value="">choose a profile</option>
|
||||||
|
{{ range $i := .config.DownloadProfiles }}
|
||||||
|
<option>{{ $i.Name }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>destination</th>
|
||||||
|
<td>
|
||||||
|
<select x-on:change="update_destination()" class="pure-input-1-2" x-model="destination_chosen">
|
||||||
|
<option value="-">leave in {{ .config.Server.DownloadPath }}</option>
|
||||||
|
{{ range $i := .config.Destinations }}
|
||||||
|
<option>{{ $i.Name }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<td>
|
||||||
|
<button class="pure-button" @click="start()">start download</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
{{ define "js" }}
|
||||||
|
<script>
|
||||||
|
function popup_create() {
|
||||||
|
return {
|
||||||
|
profile_chosen: null,
|
||||||
|
destination_chosen: null,
|
||||||
|
start() {
|
||||||
|
let op = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({action: 'start'}),
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
};
|
||||||
|
fetch('/rest/fetch', op)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(info => {
|
||||||
|
console.log(info)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{{ end }}
|
||||||
|
|
44
web/web.go
44
web/web.go
@ -317,15 +317,17 @@ func fetchInfoRESTHandler(dm *download.Manager) func(w http.ResponseWriter, r *h
|
|||||||
func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Manager) func(w http.ResponseWriter, r *http.Request) {
|
func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Manager) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
method := r.Method
|
||||||
|
|
||||||
// if they refreshed the popup, just load the existing object, don't
|
// if they refreshed the popup, just load the existing object, don't
|
||||||
// create a new one
|
// create a new one
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
idString := vars["id"]
|
idString := vars["id"]
|
||||||
|
|
||||||
idInt, err := strconv.ParseInt(idString, 10, 32)
|
idInt, idOK := strconv.ParseInt(idString, 10, 32)
|
||||||
|
|
||||||
|
if method == "GET" && idOK == nil && idInt > 0 {
|
||||||
// existing, load it up
|
// existing, load it up
|
||||||
if err == nil && idInt > 0 {
|
|
||||||
|
|
||||||
dl, err := dm.GetDlById(int(idInt))
|
dl, err := dm.GetDlById(int(idInt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -346,7 +348,9 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
} else if method == "POST" {
|
||||||
|
// creating a new one
|
||||||
|
panic("should not get here")
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
url, present := query["url"]
|
url, present := query["url"]
|
||||||
@ -356,14 +360,7 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
|
|||||||
fmt.Fprint(w, "No url supplied")
|
fmt.Fprint(w, "No url supplied")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
log.Printf("popup for %s (POST)", url)
|
||||||
log.Printf("popup for %s", url)
|
|
||||||
// check the URL for a sudden but inevitable betrayal
|
|
||||||
if strings.Contains(url[0], cs.Config.Server.Address) {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
fmt.Fprint(w, "you mustn't gropple your gropple :-)")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the new download
|
// create the new download
|
||||||
newDL := download.NewDownload(url[0], cs.Config)
|
newDL := download.NewDownload(url[0], cs.Config)
|
||||||
@ -384,5 +381,30 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// a GET, show the popup so they can start the download (or just close
|
||||||
|
// the popup if they didn't mean it)
|
||||||
|
query := r.URL.Query()
|
||||||
|
url, present := query["url"]
|
||||||
|
|
||||||
|
if !present {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
fmt.Fprint(w, "No url supplied")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/popup_create.tmpl")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
templateData := map[string]interface{}{"config": cs.Config, "url": url[0]}
|
||||||
|
|
||||||
|
err = t.ExecuteTemplate(w, "layout", templateData)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user