[feat] directly play video
This commit is contained in:
@@ -239,7 +239,15 @@ var vm = new Vue({
|
|||||||
var reqPath = this.getEncodePath(f.name)
|
var reqPath = this.getEncodePath(f.name)
|
||||||
// TODO: fix here tomorrow
|
// TODO: fix here tomorrow
|
||||||
if (f.type == "file") {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
loadFileOrDir(reqPath);
|
loadFileOrDir(reqPath);
|
||||||
|
|||||||
49
assets/video-player.html
Normal file
49
assets/video-player.html
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Video Player - [[.FileName]]</title>
|
||||||
|
<style>
|
||||||
|
body, html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: #000;
|
||||||
|
}
|
||||||
|
.video-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
video {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #fff;
|
||||||
|
font-size: 24px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="video-container">
|
||||||
|
<video id="videoPlayer" controls autoplay>
|
||||||
|
<source src="[[.VideoURL]]" type="video/[[.Extension]]">
|
||||||
|
Your browser does not support the video tag.
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
var video = document.getElementById('videoPlayer');
|
||||||
|
video.focus();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -103,6 +103,7 @@ func NewHTTPStaticServer(root string, noIndex bool) *HTTPStaticServer {
|
|||||||
// routers for Apple *.ipa
|
// routers for Apple *.ipa
|
||||||
m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist)
|
m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist)
|
||||||
m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink)
|
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.hIndex).Methods("GET", "HEAD")
|
||||||
m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST")
|
m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST")
|
||||||
@@ -816,3 +817,28 @@ func checkFilename(name string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user