Skip to content

Commit 6ade13e

Browse files
nmanderylunny
authored andcommitted
serve video files using the HTML5 video tag (#418)
* serve video files using the HTML5 video tag * lint fix: add comment to IsVideoFile
1 parent 8559d6f commit 6ade13e

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

conf/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ file_history = History
431431
file_view_raw = View Raw
432432
file_permalink = Permalink
433433
file_too_large = This file is too large to be shown
434+
video_not_supported_in_browser = Your browser doesn't support HTML5 video tag.
434435

435436
editor.new_file = New file
436437
editor.upload_file = Upload file

modules/base/tool.go

+5
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,8 @@ func IsImageFile(data []byte) bool {
494494
func IsPDFFile(data []byte) bool {
495495
return strings.Index(http.DetectContentType(data), "application/pdf") != -1
496496
}
497+
498+
// IsVideoFile detectes if data is an video format
499+
func IsVideoFile(data []byte) bool {
500+
return strings.Index(http.DetectContentType(data), "video/") != -1
501+
}

routers/repo/view.go

+2
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
198198

199199
case base.IsPDFFile(buf):
200200
ctx.Data["IsPDFFile"] = true
201+
case base.IsVideoFile(buf):
202+
ctx.Data["IsVideoFile"] = true
201203
case base.IsImageFile(buf):
202204
ctx.Data["IsImageFile"] = true
203205
}

templates/repo/view_file.tmpl

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<div class="view-raw ui center">
4444
{{if .IsImageFile}}
4545
<img src="{{EscapePound $.RawFileLink}}">
46+
{{else if .IsVideoFile}}
47+
<video controls src="{{EscapePound $.RawFileLink}}">
48+
<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
49+
</video>
4650
{{else if .IsPDFFile}}
4751
<iframe width="100%" height="600px" src="{{AppSubUrl}}/plugins/pdfjs-1.4.20/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
4852
{{else}}

0 commit comments

Comments
 (0)