From 47ad1fe724bcd4b78ef36f508ce962b5dce9dc7e Mon Sep 17 00:00:00 2001 From: Nico Mandery Date: Mon, 19 Dec 2016 19:27:27 +0100 Subject: [PATCH 1/2] serve video files using the HTML5 video tag --- conf/locale/locale_en-US.ini | 1 + modules/base/tool.go | 4 ++++ routers/repo/view.go | 2 ++ templates/repo/view_file.tmpl | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 654498cd788dd..eb56120deba73 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -431,6 +431,7 @@ file_history = History file_view_raw = View Raw file_permalink = Permalink file_too_large = This file is too large to be shown +video_not_supported_in_browser = Your browser doesn't support HTML5 video tag. editor.new_file = New file editor.upload_file = Upload file diff --git a/modules/base/tool.go b/modules/base/tool.go index e41d1ca46812c..230577ce141a4 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -494,3 +494,7 @@ func IsImageFile(data []byte) bool { func IsPDFFile(data []byte) bool { return strings.Index(http.DetectContentType(data), "application/pdf") != -1 } + +func IsVideoFile(data []byte) bool { + return strings.Index(http.DetectContentType(data), "video/") != -1 +} diff --git a/routers/repo/view.go b/routers/repo/view.go index 4417383bdc7ea..7e7ad0b923ee8 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -198,6 +198,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st case base.IsPDFFile(buf): ctx.Data["IsPDFFile"] = true + case base.IsVideoFile(buf): + ctx.Data["IsVideoFile"] = true case base.IsImageFile(buf): ctx.Data["IsImageFile"] = true } diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 68e8444768acd..08d77c3f37e6e 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -43,6 +43,10 @@
{{if .IsImageFile}} + {{else if .IsVideoFile}} + {{else if .IsPDFFile}} {{else}} From c9cef31d0bb765253cd3988200c5c86983b142d4 Mon Sep 17 00:00:00 2001 From: Gogs Date: Tue, 20 Dec 2016 08:34:30 +0100 Subject: [PATCH 2/2] lint fix: add comment to IsVideoFile --- modules/base/tool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/base/tool.go b/modules/base/tool.go index 230577ce141a4..1722c88ac8536 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -495,6 +495,7 @@ func IsPDFFile(data []byte) bool { return strings.Index(http.DetectContentType(data), "application/pdf") != -1 } +// IsVideoFile detectes if data is an video format func IsVideoFile(data []byte) bool { return strings.Index(http.DetectContentType(data), "video/") != -1 }