[update] Ignore file on size or mime type
This commit is contained in:
+3
-2
@@ -21,14 +21,15 @@
|
|||||||
"homepage": "https://github.com/brunosimon/keppler",
|
"homepage": "https://github.com/brunosimon/keppler",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^1.5.1",
|
"chokidar": "^1.5.1",
|
||||||
"socket.io-client": "^1.4.6",
|
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
"diff": "^2.2.3",
|
"diff": "^2.2.3",
|
||||||
"express": "^4.13.4",
|
"express": "^4.13.4",
|
||||||
"helmet": "^2.1.0",
|
"helmet": "^2.1.0",
|
||||||
"ip": "^1.1.3",
|
"ip": "^1.1.3",
|
||||||
|
"mime": "^1.3.4",
|
||||||
"pug": "^2.0.0-beta4",
|
"pug": "^2.0.0-beta4",
|
||||||
"slug": "^0.9.1",
|
"slug": "^0.9.1",
|
||||||
"socket.io": "^1.4.6"
|
"socket.io": "^1.4.6",
|
||||||
|
"socket.io-client": "^1.4.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ The project URL appears. Share it with the viewers on the same wifi.
|
|||||||
|
|
||||||
### Todo
|
### Todo
|
||||||
|
|
||||||
- [ ] Ignore too big files
|
|
||||||
- [ ] Ignore non txt files
|
|
||||||
- [ ] NPM package
|
- [ ] NPM package
|
||||||
|
|
||||||
### Futur features
|
### Futur features
|
||||||
|
|||||||
+20
-17
@@ -46,6 +46,26 @@ class Files
|
|||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_version( _path, _content )
|
||||||
|
{
|
||||||
|
// Set up
|
||||||
|
let normalized_path = paths.normalize( _path )
|
||||||
|
|
||||||
|
// Retrieve file
|
||||||
|
let file = this.get( normalized_path, true )
|
||||||
|
|
||||||
|
if( _content )
|
||||||
|
{
|
||||||
|
// Create version
|
||||||
|
file.create_version( _content )
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save
|
||||||
|
this.last_version_date = new Date()
|
||||||
|
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
get( _path, _force_creation )
|
get( _path, _force_creation )
|
||||||
{
|
{
|
||||||
// Params
|
// Params
|
||||||
@@ -75,23 +95,6 @@ class Files
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
create_version( _path, _content )
|
|
||||||
{
|
|
||||||
// Set up
|
|
||||||
let normalized_path = paths.normalize( _path )
|
|
||||||
|
|
||||||
// Retrieve file
|
|
||||||
let file = this.get( normalized_path, true )
|
|
||||||
|
|
||||||
// Create version
|
|
||||||
file.create_version( _content )
|
|
||||||
|
|
||||||
// Save
|
|
||||||
this.last_version_date = new Date()
|
|
||||||
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
delete( _path )
|
delete( _path )
|
||||||
{
|
{
|
||||||
// Set up
|
// Set up
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "code-spectator-site",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/brunosimon/code-spectactor"
|
|
||||||
},
|
|
||||||
"author": "Bruno Simon",
|
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/brunosimon/code-spectactor/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/brunosimon/code-spectactor",
|
|
||||||
"dependencies": {
|
|
||||||
"colors": "^1.1.2",
|
|
||||||
"diff": "^2.2.3",
|
|
||||||
"express": "^4.13.4",
|
|
||||||
"helmet": "^2.1.0",
|
|
||||||
"ip": "^1.1.3",
|
|
||||||
"pug": "^2.0.0-beta4",
|
|
||||||
"slug": "^0.9.1",
|
|
||||||
"socket.io": "^1.4.6"
|
|
||||||
},
|
|
||||||
"devDependencies": {}
|
|
||||||
}
|
|
||||||
@@ -68,8 +68,15 @@ application.controller(
|
|||||||
if( $scope.version )
|
if( $scope.version )
|
||||||
$scope.version.active = false;
|
$scope.version.active = false;
|
||||||
|
|
||||||
|
if( file.versions.length )
|
||||||
|
{
|
||||||
$scope.version = file.versions[ file.versions.length - 1 ];
|
$scope.version = file.versions[ file.versions.length - 1 ];
|
||||||
$scope.version.active = true
|
$scope.version.active = true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$scope.version = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.version_click = function( version )
|
$scope.version_click = function( version )
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -302,7 +302,7 @@ body.project
|
|||||||
bottom 0
|
bottom 0
|
||||||
background #31344a
|
background #31344a
|
||||||
|
|
||||||
section.no-file
|
section.big-centered-text
|
||||||
position absolute
|
position absolute
|
||||||
top 0
|
top 0
|
||||||
left 0
|
left 0
|
||||||
@@ -505,4 +505,3 @@ body.project
|
|||||||
&.added
|
&.added
|
||||||
border 1px solid #b0ea23
|
border 1px solid #b0ea23
|
||||||
background rgba(176, 234, 35, 0.1)
|
background rgba(176, 234, 35, 0.1)
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ div(ng-controller="ProjectController as controller",ng-init="init('" + project_s
|
|||||||
a.title(href="/")
|
a.title(href="/")
|
||||||
| Keppler
|
| Keppler
|
||||||
|
|
||||||
|
|
||||||
aside.aside
|
aside.aside
|
||||||
header.aside-header
|
header.aside-header
|
||||||
.name
|
.name
|
||||||
@@ -76,10 +75,19 @@ div(ng-controller="ProjectController as controller",ng-init="init('" + project_s
|
|||||||
| Mark all as read
|
| Mark all as read
|
||||||
|
|
||||||
section.main
|
section.main
|
||||||
section.no-file(ng-if="!file")
|
section.no-file.big-centered-text(ng-if="!file")
|
||||||
.text
|
.text
|
||||||
| Choose a file
|
| Choose a file
|
||||||
section.file(ng-if="file")
|
section.no-content.big-centered-text(ng-if="file && (!file.versions || file.versions.length === 0)")
|
||||||
|
.text
|
||||||
|
| Content not available
|
||||||
|
section.file(ng-if="file && file.versions && file.versions.length > 0",ng-class="!file.versions || file.versions.length === 0 ? 'no-content' : ''")
|
||||||
|
header.file-header
|
||||||
|
.content
|
||||||
|
span.path
|
||||||
|
| {{file.path.directory}}/
|
||||||
|
span.name
|
||||||
|
| {{file.name}}
|
||||||
nav.versions-nav
|
nav.versions-nav
|
||||||
a.version(href="#",ng-repeat="_version in file.versions",ng-click="version_click(_version)",ng-class="_version.active ? 'active' : 'inactive'")
|
a.version(href="#",ng-repeat="_version in file.versions",ng-click="version_click(_version)",ng-class="_version.active ? 'active' : 'inactive'")
|
||||||
.background
|
.background
|
||||||
@@ -97,12 +105,6 @@ div(ng-controller="ProjectController as controller",ng-init="init('" + project_s
|
|||||||
.fill(style="width:{{_version.diff_percent}};")
|
.fill(style="width:{{_version.diff_percent}};")
|
||||||
.percent(style="width:{{_version.diff_percent}};")
|
.percent(style="width:{{_version.diff_percent}};")
|
||||||
| {{_version.diff_percent}}
|
| {{_version.diff_percent}}
|
||||||
header.file-header
|
|
||||||
.content
|
|
||||||
span.path
|
|
||||||
| {{file.path.directory}}/
|
|
||||||
span.name
|
|
||||||
| {{file.name}}
|
|
||||||
section.code
|
section.code
|
||||||
.lines
|
.lines
|
||||||
pre
|
pre
|
||||||
@@ -117,4 +119,5 @@ div(ng-controller="ProjectController as controller",ng-init="init('" + project_s
|
|||||||
span.value
|
span.value
|
||||||
| {{ _difference.value }}
|
| {{ _difference.value }}
|
||||||
|
|
||||||
|
|
||||||
include ../../partials/footer.pug
|
include ../../partials/footer.pug
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ let chokidar = require( 'chokidar' ),
|
|||||||
colors = require( 'colors' ),
|
colors = require( 'colors' ),
|
||||||
ip = require( 'ip' ),
|
ip = require( 'ip' ),
|
||||||
socket_io_client = require( 'socket.io-client' ),
|
socket_io_client = require( 'socket.io-client' ),
|
||||||
fs = require( 'fs' )
|
fs = require( 'fs' ),
|
||||||
|
mime = require( 'mime' )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watcher class
|
* Watcher class
|
||||||
@@ -87,13 +88,34 @@ class Watcher
|
|||||||
this.watcher.on( 'add', ( _path ) =>
|
this.watcher.on( 'add', ( _path ) =>
|
||||||
{
|
{
|
||||||
// Set up
|
// Set up
|
||||||
let relative_path = _path.replace( process.cwd(), '.' )
|
let relative_path = _path.replace( process.cwd(), '.' ),
|
||||||
|
mime_type = mime.lookup( relative_path ),
|
||||||
|
file = {}
|
||||||
|
|
||||||
|
file.path = relative_path;
|
||||||
|
file.can_read = true;
|
||||||
|
|
||||||
|
// Test mime type
|
||||||
|
if( mime_type.match(/^(audio)|(video)|(image)/) )
|
||||||
|
{
|
||||||
|
file.can_read = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve stats
|
||||||
|
fs.stat( _path, ( error, stats ) =>
|
||||||
|
{
|
||||||
|
if( stats.size > 999999 )
|
||||||
|
file.can_read = false
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
fs.readFile( _path, ( error, data ) =>
|
fs.readFile( _path, ( error, data ) =>
|
||||||
{
|
{
|
||||||
|
if( file.can_read )
|
||||||
|
file.content = data.toString()
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
this.socket.emit( 'create_file', { path: relative_path, content: data.toString() } )
|
this.socket.emit( 'create_file', file )
|
||||||
|
} )
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
@@ -107,13 +129,34 @@ class Watcher
|
|||||||
this.watcher.on( 'change', ( _path ) =>
|
this.watcher.on( 'change', ( _path ) =>
|
||||||
{
|
{
|
||||||
// Set up
|
// Set up
|
||||||
let relative_path = _path.replace( process.cwd(), '.' )
|
let relative_path = _path.replace( process.cwd(), '.' ),
|
||||||
|
mime_type = mime.lookup( relative_path ),
|
||||||
|
file = {}
|
||||||
|
|
||||||
|
file.path = relative_path;
|
||||||
|
file.can_read = true;
|
||||||
|
|
||||||
|
// Test mime type
|
||||||
|
if( mime_type.match(/^(audio)|(video)|(image)/) )
|
||||||
|
{
|
||||||
|
file.can_read = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve stats
|
||||||
|
fs.stat( _path, ( error, stats ) =>
|
||||||
|
{
|
||||||
|
if( stats.size > 999999 )
|
||||||
|
file.can_read = false
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
fs.readFile( _path, ( error, data ) =>
|
fs.readFile( _path, ( error, data ) =>
|
||||||
{
|
{
|
||||||
|
if( file.can_read )
|
||||||
|
file.content = data.toString()
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
this.socket.emit( 'update_file', { path: relative_path, content: data.toString() } )
|
this.socket.emit( 'update_file', file )
|
||||||
|
} )
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
|
|||||||
Reference in New Issue
Block a user