diff --git a/main.go b/main.go index 0b7c707..05bcdc7 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,11 @@ type DownloadFormats struct { audioOnly bool } +type URLValidationCtx struct { + URL string + Valid bool +} + type apiMessageResponse struct { Message string } @@ -169,6 +174,7 @@ func main() { } }, ) + handler.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { ctx := NewContext(r) formats := []DownloadFormats{} @@ -185,6 +191,30 @@ func main() { } }) + handler.HandleFunc("/valid-link", func(w http.ResponseWriter, r *http.Request) { + + if r.Method != "POST" { + w.WriteHeader(400) + return + } + + err := r.ParseForm() + if err != nil { + log.Println(err.Error()) + w.WriteHeader(400) + return + } + + url := r.FormValue("URL") + + ctx := URLValidationCtx{ + URL: url, + Valid: isValidURL(url), + } + + templates.ExecuteTemplate(w, "url-validation.html", ctx) + }) + wrappedHandler := NewLogger(handler) srv := http.Server{ ReadTimeout: 10 * time.Second, diff --git a/templates/download.html b/templates/download.html index b27bc81..f5a88ba 100644 --- a/templates/download.html +++ b/templates/download.html @@ -13,14 +13,21 @@

Viddle your fiddle

-
- - - +
+ + +
+