aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Mandery <nico@nmandery.net>2016-12-20 09:09:11 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2016-12-20 16:09:11 +0800
commit6ade13e86ee494ac10b36454285354dbfe36d9c0 (patch)
treefa17ee2f0012a9dbab659c0ebd37b347d79203b5
parent8559d6f267324241496b8611bc8e6f76efe869b7 (diff)
downloadgitea-6ade13e86ee494ac10b36454285354dbfe36d9c0.tar.gz
gitea-6ade13e86ee494ac10b36454285354dbfe36d9c0.zip
serve video files using the HTML5 video tag (#418)
* serve video files using the HTML5 video tag * lint fix: add comment to IsVideoFile
-rw-r--r--conf/locale/locale_en-US.ini1
-rw-r--r--modules/base/tool.go5
-rw-r--r--routers/repo/view.go2
-rw-r--r--templates/repo/view_file.tmpl4
4 files changed, 12 insertions, 0 deletions
diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini
index 654498cd78..eb56120deb 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 e41d1ca468..1722c88ac8 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -494,3 +494,8 @@ func IsImageFile(data []byte) bool {
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
+}
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 4417383bdc..7e7ad0b923 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 68e8444768..08d77c3f37 100644
--- a/templates/repo/view_file.tmpl
+++ b/templates/repo/view_file.tmpl
@@ -43,6 +43,10 @@
<div class="view-raw ui center">
{{if .IsImageFile}}
<img src="{{EscapePound $.RawFileLink}}">
+ {{else if .IsVideoFile}}
+ <video controls src="{{EscapePound $.RawFileLink}}">
+ <strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
+ </video>
{{else if .IsPDFFile}}
<iframe width="100%" height="600px" src="{{AppSubUrl}}/plugins/pdfjs-1.4.20/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
{{else}}