all repos — gopipe @ 651b74409cb974602d050be17b8f7158ac301e2c

Embed YouTube videos on Telegram, Discord and more!

add "safe" template function
Marco Andronaco andronacomarco@gmail.com
Tue, 19 Nov 2024 17:52:19 +0100
commit

651b74409cb974602d050be17b8f7158ac301e2c

parent

8e4f97e36220a7548c4bc0b8f16b6cd4bdd1ad83

3 files changed, 9 insertions(+), 5 deletions(-)

jump to
M src/app/handlers.gosrc/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.gosrc/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.tmpltemplates/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 }}