From 6e3f7062a8e2e3b832503422948639ef06a51962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20P=C4=99czek?= Date: Wed, 15 Jun 2016 11:06:46 +0200 Subject: [PATCH 1/2] File format validation --- .gitignore | 1 + playlist.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 08e8372..bb92dfd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ Playback-win32.zip Playback.app Playback.app.zip .DS_Store +.idea diff --git a/playlist.js b/playlist.js index 5e666b9..9140b8e 100644 --- a/playlist.js +++ b/playlist.js @@ -10,6 +10,8 @@ var concat = require('concat-stream') var noop = function () {} +var allowedExts = ["mpg", "mkv", "mp4", "mp3", "vtt", "srt"] + module.exports = function () { var that = new events.EventEmitter() @@ -141,6 +143,10 @@ module.exports = function () { file.length = st.size file.name = path.basename(link) + var filenameArr = file.name.split(".") + file.extension = filenameArr[filenameArr.length-1].toLowerCase() + if (allowedExts.indexOf(file.extension) == -1) return cb("File format not supported") + file.createReadStream = function (opts) { return fs.createReadStream(link, opts) } From 50295923eba064f6f48cb17cc64e40acd1e62780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20P=C4=99czek?= Date: Wed, 15 Jun 2016 15:24:50 +0200 Subject: [PATCH 2/2] Hotfix for format validation --- playlist.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/playlist.js b/playlist.js index 9140b8e..41e4f11 100644 --- a/playlist.js +++ b/playlist.js @@ -10,7 +10,7 @@ var concat = require('concat-stream') var noop = function () {} -var allowedExts = ["mpg", "mkv", "mp4", "mp3", "vtt", "srt"] +var allowedExts = ['mpg', 'mkv', 'mp4', 'mp3', 'vtt', 'srt'] module.exports = function () { var that = new events.EventEmitter() @@ -143,9 +143,8 @@ module.exports = function () { file.length = st.size file.name = path.basename(link) - var filenameArr = file.name.split(".") - file.extension = filenameArr[filenameArr.length-1].toLowerCase() - if (allowedExts.indexOf(file.extension) == -1) return cb("File format not supported") + file.extension = file.name.split(".").pop().toLowerCase() + if (allowedExts.indexOf(file.extension) === -1) return cb("File format not supported") file.createReadStream = function (opts) { return fs.createReadStream(link, opts)