Skip to content

Commit

Permalink
添加encrypt和noencrypt目录是否存在的判断,如果不存在,则创建之
Browse files Browse the repository at this point in the history
  • Loading branch information
hauk0101 committed Aug 14, 2017
1 parent 2f1389e commit be835fd
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 11 deletions.
16 changes: 8 additions & 8 deletions app/controllers/encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function encryptHandle(options, callback) {
var _videoPath = options.noencryptPath + '/' + options.fileName;
var _keyInfoPath = './public/key/key_info.key';
var _outputPath = _encryptPath + '/playlist.m3u8';
console.log('++', _encryptPath)
//创建对应的文件目录
if (fs.existsSync(_encryptPath)) {
encryptFun(options, callback);

} else {
//如果没有encrypt目录,则创建之
if(!fs.existsSync(options.encryptPath)){
fs.mkdirSync(options.encryptPath);
};
//如果没有对应的文件目录,则创建之
if(!fs.existsSync(_encryptPath)){
fs.mkdirSync(_encryptPath);
encryptFun(options, callback);
}
};
encryptFun(options, callback);
console.log(fs.existsSync(options.encryptPath + '/' + _name));
}

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
*/

var multer = require('multer');
var fs = require('fs');

var storage = multer.diskStorage({
//设置上传后文件路径,如果文件夹路径不存在则会自动创建
destination: function (req, file, cb) {
cb(null,'./public/videos/noencrypt');
var _noencryptPath = './public/videos/noencrypt';
if(!fs.existsSync(_noencryptPath)){
fs.mkdirSync(_noencryptPath);
}
cb(null,_noencryptPath);
},
//重命名上传的文件,并添加后缀
filename:function(req,file,cb){
Expand Down
2 changes: 1 addition & 1 deletion app/public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//post请求的相关数据
var postData = {
encrypt_data: {}
}
};

//入口
init();
Expand Down
2 changes: 1 addition & 1 deletion app/routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ router.post('/encrypt',function (req,res) {
console.log(req.body);
encrypt(req.body,function(err,data){
console.log(err,data);

res.json(err,data);
});
//TODO 检查对应的文件夹是否存在,如果存在则开始执行ffmpeg加密操作,执行完后跳转至对应的index界面并返回参数

Expand Down
16 changes: 16 additions & 0 deletions test/playlist.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:12
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="https://localhost:3000/key/encrypt.key"
#EXTINF:11.387133,
playlist0.ts
#EXTINF:11.011733,
playlist1.ts
#EXTINF:9.051311,
playlist2.ts
#EXTINF:8.592489,
playlist3.ts
#EXTINF:6.506933,
playlist4.ts
#EXT-X-ENDLIST
Binary file added test/playlist0.ts
Binary file not shown.
Binary file added test/playlist1.ts
Binary file not shown.
Binary file added test/playlist2.ts
Binary file not shown.
Binary file added test/playlist3.ts
Binary file not shown.
Binary file added test/playlist4.ts
Binary file not shown.
39 changes: 39 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PC HLS video</title>
<link href="https://cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css" rel="stylesheet">
</head>
<body>

<h1>PC 端播放 HLS(<code>.m3u8</code>) 视频</h1>
<p>借助 video.js 和 videojs-contrib-hls</p>
<p>由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域</p>

<video id=example-video width=600 height=300 class="video-js vjs-default-skin" controls>
<source
src="playlist.m3u8"
type="application/x-mpegURL">
</video>
<!--<script src="app/public/javascripts/video.js"></script>-->
<!--<script src="app/public/javascripts/videojs-contrib-hls.min.js"></script>-->


<script src="https://vjs.zencdn.net/5.19/video.min.js"></script>
<!-- PC 端浏览器不支持播放 hls 文件(m3u8), 需要 videojs-contrib-hls 来给我们解码 -->
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
<script>
var player = videojs('example-video');
player.play();
</script>
<!--<script>-->
<!--// XMLHttpRequest cannot load https://xxx/video.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://192.168.198.98:8000' is therefore not allowed access.-->
<!--// 由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域-->
<!--var player = videojs('hls-video');-->
<!--player.play();-->
<!--</script>-->
</body>
</html>

0 comments on commit be835fd

Please sign in to comment.