diff --git a/bin/config.default.json b/bin/config.default.json index 6f80438..7abe140 100644 --- a/bin/config.default.json +++ b/bin/config.default.json @@ -1,5 +1,10 @@ { - "debug" : false, - "port" : 1571, - "max_file_size" : 2000 + "debug" : false, + "port" : 1571, + "max_file_size": 99999, + "exclude" : + [ + "node_modules/**", + "vendors/**" + ] } diff --git a/bin/keppler.class.js b/bin/keppler.class.js index 14015fa..da3e8a2 100644 --- a/bin/keppler.class.js +++ b/bin/keppler.class.js @@ -55,6 +55,9 @@ class Keppler if( typeof _options.max_file_size === 'undefined' ) _options.max_file_size = default_config.max_file_size + if( typeof _options.exclude === 'undefined' ) + _options.exclude = default_config.exclude + // Save this.options = _options } @@ -101,6 +104,7 @@ class Keppler domain : this.options.domain, debug : this.options.debug, max_file_size: this.options.max_file_size, + exclude : this.options.exclude, name : this.arguments[ 0 ] } ) } diff --git a/package.json b/package.json index 238feb7..436c411 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "helmet": "^2.1.0", "ip": "^1.1.3", "mime": "^1.3.4", + "minimatch": "^3.0.3", "pug": "^2.0.0-beta4", "slug": "^0.9.1", "socket.io": "^1.4.6", diff --git a/test-folder/vendors/excluded-file.txt b/test-folder/vendors/excluded-file.txt new file mode 100644 index 0000000..e381795 --- /dev/null +++ b/test-folder/vendors/excluded-file.txt @@ -0,0 +1 @@ +This file shouldn't be include diff --git a/watcher/watcher.class.js b/watcher/watcher.class.js index f4292c9..f3913b9 100644 --- a/watcher/watcher.class.js +++ b/watcher/watcher.class.js @@ -7,7 +7,8 @@ let chokidar = require( 'chokidar' ), ip = require( 'ip' ), socket_io_client = require( 'socket.io-client' ), fs = require( 'fs' ), - mime = require( 'mime' ) + mime = require( 'mime' ), + minimatch = require( 'minimatch' ) /** * Watcher class @@ -104,9 +105,22 @@ class Watcher file.can_read = false; } + // Test exclusion + for( let _exclude_key in this.options.exclude ) + { + // Set up + let _exclude = this.options.exclude[ _exclude_key ], + relative_path = _path.replace( process.cwd() + '/', '' ) + + // Match excluded path + if( minimatch( relative_path, _exclude ) ) + return; + } + // Retrieve stats fs.stat( _path, ( error, stats ) => { + // Max file size if( stats.size > this.options.max_file_size ) file.can_read = false @@ -145,9 +159,22 @@ class Watcher file.can_read = false; } + // Test exclusion + for( let _exclude_key in this.options.exclude ) + { + // Set up + let _exclude = this.options.exclude[ _exclude_key ], + relative_path = _path.replace( process.cwd() + '/', '' ) + + // Match excluded path + if( minimatch( relative_path, _exclude ) ) + return; + } + // Retrieve stats fs.stat( _path, ( error, stats ) => { + // Test max file size if( stats.size > this.options.max_file_size ) file.can_read = false