Skip to content

Commit

Permalink
Angular upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Speakman committed Aug 5, 2015
1 parent d90c627 commit a2427d9
Show file tree
Hide file tree
Showing 36 changed files with 1,097 additions and 12,671 deletions.
32 changes: 4 additions & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

public/build
.bower-*/
bower_components
public/css/styles.css
public/js/scripts.js
93 changes: 56 additions & 37 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
var gulp = require("gulp");
var uglify = require("gulp-uglify");
var concat = require("gulp-concat");
var streamqueue = require('streamqueue');
var minifyCSS = require("gulp-minify-css");

gulp.task("js", function () {

var stream = streamqueue({ objectMode: true });

stream.queue(
gulp.src([
"public/js/vendor/*.min.js"
])
);

stream.queue(
gulp.src([
"public/js/vendor/*.js",
"!public/js/vendor/*.min.js",
"public/js/script.js"
])
.pipe(uglify({preserveComments: "some"}))
);

return stream.done()
.pipe(concat("scripts.js"))
.pipe(gulp.dest("public/build/"));
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var minifyCSS = require('gulp-minify-css');
var bower = require('gulp-bower');
var mainBowerFiles = require('main-bower-files');
var order = require('gulp-order');

gulp.task('js', function () {

// Angular app
var scripts = [
'app/**/*.js'
]

return gulp
.src(scripts)
.pipe(concat('app.js'))
.pipe(gulp.dest('public/js/'))

});

gulp.task('vendor', ['bower'], function () {

// Bower dependencies
var bowerScripts = mainBowerFiles('**/*.js');

return gulp
.src(bowerScripts)
.pipe(order([
'*angular.js',
'*angular-sanitize.js'
]))
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest('public/js/'))

});

gulp.task("css", function () {
gulp.task('css', ['bower'], function () {

var stream = streamqueue({ objectMode: true });
// Bower dependencies
var bowerStyles = mainBowerFiles('**/*.css');

stream.queue(
gulp.src("public/css/*.css")
);
// App styles
var styles = [
'public/css/style.css'
]

return stream.done()
.pipe(concat("style.css"))
return gulp
.src(bowerStyles.concat(styles))
.pipe(concat('styles.css'))
.pipe(minifyCSS())
.pipe(gulp.dest("public/build/"));
.pipe(gulp.dest('public/css/'))

});

gulp.task('bower', function() {
return bower();
});

gulp.task('watch', function() {
gulp.watch('app/**/*.js', ['js']);
});

gulp.task('default', ['js', 'css']);
gulp.task('default', ['bower', 'vendor', 'js', 'css']);
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sendsh.it
The [sendsh.it](https://sendsh.it/) client-side javascript will read and encrypt a file in your browser using the [Triplesec](http://keybase.github.io/triplesec/) library with a random key generated by the [SJCL library](http://bitwiseshiftleft.github.io/sjcl/) PRNG.
The [sendsh.it](https://sendsh.it/) client-side javascript will read and encrypt a file in your browser using the [Triplesec](http://keybase.github.io/triplesec/) library with a random key generated by its PRNG.

The encrypted file is then uploaded to the backend node.js application which stores it in mongo's [GridFS](http://docs.mongodb.org/manual/core/gridfs/) and returns a unique ID. This is combined with your generated key to produce a unique url you can share with someone else. Once they visit the url the site will download the file and decrypt it in their browser.

Expand All @@ -9,12 +9,12 @@ Files are deleted after being downloaded or once they are over 24 hours old.
* `git clone git@github.com:threesquared/sendsh.it.git`
* `npm install`
* `gulp`
* `node app.js`
* `node server.js`

## Configure
Set your mongodb and express parameters in the top of app.js.
Set your mongodb and express parameters in the top of server.js.

The app is also configured to read the env parameters from an [Openshift](https://www.openshift.com/) environment. There is also an openshift deploy hook to run gulp.
The server is also configured to read the env parameters from an [Openshift](https://www.openshift.com/) environment. There is also an openshift deploy hook to run gulp.

## Disclaimer
I am not an expert in cryptography. If you have something important to keep secret please think about using a peer reviewed and audited service. This is just an experiment with in browser encryption and node.js.
100 changes: 100 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var sendshit = angular.module('sendsh.it', ['ngRoute', 'ngSanitize', 'ngProgressLite']);

sendshit.config(['$routeProvider', 'ngProgressLiteProvider', function($routeProvider, ngProgressLiteProvider) {

if(!window.FileReader || !window.FormData || !window.Blob) {
throw new Error('Your browser does not support required features.');
}

$routeProvider.when('/', {

controller: 'UploadController',
templateUrl: 'views/upload.html'

}).when('/:downloadId/:downloadPassword', {

controller: 'DownloadController',
templateUrl: 'views/download.html'

}).otherwise({

redirectTo: '/'

});

ngProgressLiteProvider.settings.speed = 1;
ngProgressLiteProvider.settings.minimum = 0.1;
ngProgressLiteProvider.settings.ease = 'linear';

}]);

sendshit.factory('messages', ['$rootScope', function($rootScope){

var message = '';
var messages = {};

messages.addMsg = function(msg, ellipsis) {

ellipsis = typeof ellipsis !== 'undefined' ? ellipsis : false;

if(ellipsis === true) {
msg = msg + '<i class="ellipsis"><i>.</i><i>.</i><i>.</i></i>';
}

message = msg;

$rootScope.$broadcast('message:updated', message);

};

messages.getMsg = function() {
return message;
};

return messages;

}]);

sendshit.factory('triplesecProgress', ['$log', 'ngProgressLite', function($log, ngProgressLite) {

var triplesecProgress = {};

triplesecProgress.updateProgress = function(obj) {

var percent = obj.i / obj.total;

if(obj.what == 'pbkdf2 (pass 1)' || obj.what == 'pbkdf2 (pass 2)'){
this.logProgress('Running PBKDF2', percent);
}

if(obj.what == 'scrypt'){
this.logProgress('Scrypt', percent);
}

if(obj.what == 'salsa20'){
this.logProgress('Salsa20', percent);
}

if(obj.what == 'twofish'){
this.logProgress('Twofish-CTR', percent);
}

if(obj.what == 'aes'){
this.logProgress('AES-256-CTR', percent);
}

if(obj.what == 'HMAC-SHA512-SHA3'){
this.logProgress('Generating HMAC', percent);
}

};

triplesecProgress.logProgress = function(text, percent)
{
$log.log(text + ': ' + Math.round(percent * 100) + '%');
ngProgressLite.set(parseFloat(percent.toFixed(1)));
};

return triplesecProgress;

}]);
30 changes: 30 additions & 0 deletions app/controllers/downloadController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
sendshit.controller('DownloadController', ['$scope', '$routeParams', 'decryptor', 'fileReader', 'messages', function($scope, $routeParams, decryptor, fileReader, messages) {

var password = $routeParams.downloadPassword;

decryptor.downloadFile('download?id=' + $routeParams.downloadId).then(function(data) {

var blob = new Blob([data], {type: 'application/octet-stream'});

return fileReader.readAsText(blob);

}).then(function(file) {

return decryptor.decryptFile(file, password);

}).then(function(decrypted) {

messages.addMsg('Done');
saveAs(decrypted.blob, decrypted.name);

}, function(error) {

messages.addMsg(error);

});

$scope.$on('message:updated', function(event, message) {
$scope.message = message;
});

}]);
41 changes: 41 additions & 0 deletions app/controllers/uploadController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
sendshit.controller('UploadController', ['$scope', '$q', 'encryptor', 'fileReader', 'messages', function($scope, $q, encryptor, fileReader, messages) {

$scope.fileUploaded = false;

$scope.uploadFile = function(event) {

var file = $scope.uploadedFile;

if(file.size > 5000000) {
messages.addMsg('File must be under 5MB');
return false;
}

$scope.uploadFieldText = file.name;

$q.all([fileReader.readAsDataUrl(file), encryptor.generateKey()]).then(function(data){

return encryptor.encryptFile(data[0].name, data[0].reader, data[1]);

}).then(function(encrypted) {

return encryptor.uploadFile(encrypted);

}).then(function(link) {

$scope.fileUploaded = true;
$scope.uploadLink = link;

}, function(error) {

messages.addMsg(error);

});

};

$scope.$on('message:updated', function(event, message) {
$scope.message = message;
});

}]);
17 changes: 17 additions & 0 deletions app/directives/selectOnClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sendshit.directive('selectOnClick', function () {
return {
restrict: 'A',
link: function (scope, element) {
var focusedElement;
element.on('click', function () {
if (focusedElement != this) {
this.select();
focusedElement = this;
}
});
element.on('blur', function () {
focusedElement = null;
});
}
};
});
12 changes: 12 additions & 0 deletions app/directives/uploadOnChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sendshit.directive('uploadOnChange', function() {
return {
require:"ngModel",
restrict: 'A',
link: function($scope, el, attrs, ngModel){
el.bind('change', function(event){
ngModel.$setViewValue(event.target.files[0]);
$scope.$apply();
});
}
};
});
Loading

0 comments on commit a2427d9

Please sign in to comment.