add "safe" template function
Marco Andronaco andronacomarco@gmail.com
Tue, 19 Nov 2024 17:52:19 +0100
3 files changed,
9 insertions(+),
5 deletions(-)
M
src/app/handlers.go
→
src/app/handlers.go
@@ -95,7 +95,7 @@ formatID := getFormatID(r.PathValue("formatID"))
video, format, err := getVideo(videoID, formatID) if err != nil { - http.Error(w, err500, http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return }
M
src/globals/globals.go
→
src/globals/globals.go
@@ -29,7 +29,7 @@
AdminUser string AdminPass string - funcMap = template.FuncMap{"parseFormat": parseFormat} + funcMap = template.FuncMap{"parseFormat": parseFormat, "safe": safe} ) func parseFormat(f youtube.Format) (res string) {@@ -57,3 +57,7 @@
res += codecs return } + +func safe(s string) template.HTML { + return template.HTML(s) +}
M
templates/video.tmpl
→
templates/video.tmpl
@@ -15,8 +15,8 @@ <meta property="og:site_name" content="GoPipe ({{ .Author }})" />
<meta property="twitter:image" content="{{ .Thumbnail }}" /> <meta property="twitter:player:stream:content_type" content="{{ .MimeType }}" /> {{ if .VideoURL }} - <meta property="og:video" content="{{ .VideoURL }}" /> - <meta property="og:video:secure_url" content="{{ .VideoURL }}" /> + <meta property="og:video" content="{{ safe .VideoURL }}" /> + <meta property="og:video:secure_url" content="{{ safe .VideoURL }}" /> <meta property="og:video:duration" content="{{ .Duration }}"> <meta property="og:video:type" content="{{ .MimeType }}" /> {{ end }}@@ -25,7 +25,7 @@
{{define "content" -}} <video style="width: 100%" autoplay controls> - <source src="{{ .VideoURL }}" type="{{ .MimeType }}" /> + <source src="{{ safe .VideoURL }}" type="{{ .MimeType }}" /> {{ range .Captions }} <track kind="subtitles" label="{{ .Language }}" src="/sub/{{ .VideoID }}/{{ .Language }}.vtt" srclang="{{ .Language }}" /> {{ end }}