diff --git a/assets/js/index.js b/assets/js/index.js
index cc45c87..995ce45 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -239,7 +239,15 @@ var vm = new Vue({
var reqPath = this.getEncodePath(f.name)
// TODO: fix here tomorrow
if (f.type == "file") {
- window.location.href = reqPath;
+ // check whether the file is video
+ var videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'];
+ var fileExtension = getExtention(f.name).toLowerCase();
+ if (videoExtensions.includes(fileExtension)) {
+ window.location.href = '/-/video-player' + reqPath;
+ } else {
+ window.location.href = reqPath;
+ }
+ e.preventDefault()
return;
}
loadFileOrDir(reqPath);
diff --git a/assets/video-player.html b/assets/video-player.html
new file mode 100644
index 0000000..63e86a4
--- /dev/null
+++ b/assets/video-player.html
@@ -0,0 +1,49 @@
+
+
+
+
+
+ Video Player - [[.FileName]]
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/httpstaticserver.go b/httpstaticserver.go
index 694ef59..15ddf88 100644
--- a/httpstaticserver.go
+++ b/httpstaticserver.go
@@ -103,6 +103,7 @@ func NewHTTPStaticServer(root string, noIndex bool) *HTTPStaticServer {
// routers for Apple *.ipa
m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist)
m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink)
+ m.HandleFunc("/-/video-player/{path:.*}", s.hVideoPlayer)
m.HandleFunc("/{path:.*}", s.hIndex).Methods("GET", "HEAD")
m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST")
@@ -816,3 +817,28 @@ func checkFilename(name string) error {
}
return nil
}
+
+func (s *HTTPStaticServer) hVideoPlayer(w http.ResponseWriter, r *http.Request) {
+ path := mux.Vars(r)["path"]
+ realPath := s.getRealPath(r)
+ extension := strings.ToLower(strings.TrimPrefix(filepath.Ext(path), "."))
+
+ if _, err := os.Stat(realPath); os.IsNotExist(err) {
+ http.Error(w, "File not found", http.StatusNotFound)
+ return
+ }
+
+ fileName := filepath.Base(path)
+
+ scheme := "http"
+ if r.TLS != nil {
+ scheme = "https"
+ }
+ videoURL := fmt.Sprintf("%s://%s/%s", scheme, r.Host, path)
+
+ renderHTML(w, "assets/video-player.html", map[string]interface{}{
+ "FileName": fileName,
+ "VideoURL": videoURL,
+ "Extension": extension,
+ })
+}