feat: better url validation:

- Do not accept redirects. Usually
	on yt at least, redirect means the link
	is invalid. Hence, it redirects to the home
	page.

	- This is tested and it works well. trust.

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2023-09-13 13:43:44 +03:00
parent b88ca836ef
commit 13269a7b84
2 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,6 @@
<button>Try Again
<!-- <a class="htmx-indicator" href="#" aria-busy="true"></a> -->
</button>
<mark>Internal Error. Try Again later</mark>
<strong>Internal Error. Try Again later</strong>
{{ end }}
</div>

6
yt.go
View File

@ -31,7 +31,11 @@ func isValidURL(data string) bool {
}
httpClient := &http.Client{}
httpClient := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
resp, err := httpClient.Get(data)
if err != nil {