Skip to content

Commit

Permalink
添加上传页面的校验
Browse files Browse the repository at this point in the history
  • Loading branch information
hauk0101 committed Aug 25, 2017
1 parent f2c8e1b commit 539694d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function encryptHandle(options,socket, callback) {
var _videoPath = options.noencryptPath + '/' + options.fileName;
var _keyInfoPath = './public/key/key_info.key';
var _outputPath = _encryptPath + '/playlist.m3u8';

//如果没有encrypt目录,则创建之
if(!fs.existsSync(options.encryptPath)){
fs.mkdirSync(options.encryptPath);
Expand All @@ -28,7 +29,6 @@ function encryptHandle(options,socket, callback) {
fs.mkdirSync(_encryptPath);
};
encryptFun(options,socket, callback);
console.log(fs.existsSync(options.encryptPath + '/' + _name));
}

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ function encryptFun(options,socket, callback) {
})
.on('error', function (err, stdout, stderr) {
console.log('Cannot process video: ' + err.message);
ocket.emit('encrypt-event',{msg:err.message});
socket.emit('encrypt-event',{msg:err.message});
callback(err, err.message);
});
}
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var storage = multer.diskStorage({
//设置上传后文件路径,如果文件夹路径不存在则会自动创建
destination: function (req, file, cb) {
var _noencryptPath = './public/videos/noencrypt';
//如果没有videos目录,则创建之
if(!fs.existsSync('./public/videos')){
fs.mkdirSync('./public/videos');
}
//如果没有noencrypt目录,则创建之
if(!fs.existsSync(_noencryptPath)){
fs.mkdirSync(_noencryptPath);
}
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"debug": "~2.6.3",
"ejs": "^2.5.7",
"express": "~4.15.2",
"express-session": "^1.15.5",
"fluent-ffmpeg": "^2.1.2",
"jade": "~1.11.0",
"morgan": "~1.8.1",
Expand Down
17 changes: 14 additions & 3 deletions app/views/upload.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
</head>
<body>
<h2 align="center">视频加密原型图(HLS + NodeJS + FFmpeg) Demo —— 上传视频</h2>
<form method="post" enctype="multipart/form-data" action="/upload-video">
<input type="file" name="file">
<form method="post" enctype="multipart/form-data" action="/upload-video" onsubmit="return check()">
<input id="upload-file" type="file" name="file">
<input type="submit" class="button blue" value="上传视频">
</form>


</body>
<script>
var upload_file = document.getElementById('upload-file');
function check(){
console.log(upload_file.value.length);
if(upload_file.value.length>0){
return true;
}else{
alert('请选择上传文件!');
return false;
}
}
</script>
</html>

0 comments on commit 539694d

Please sign in to comment.