diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 791ba57..c6c97f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ pages: script: - export SALT="salt_and_pepper" - export KEY="qwerty" - - export PLAYER_LIST_LOCATION="//ballephenix.gitlab.io/private/players.json.spritz" + - export PLAYER_LIST_LOCATION="//ballephenix.gitlab.io/private/players.spritz.js" - npm install - node_modules/.bin/gulp prod - node_modules/.bin/r.js -o build.js diff --git a/gulpfile.js b/gulpfile.js index b0038d3..a081d6a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,7 +42,7 @@ gulp.task('compile-results', function(){ var encryptFile = function(message){ var keyLengthInBytes = 128; - var salt = process.env.SALT || ''; + var salt = process.env.SALT || 'salt'; var stringKey = salt + (process.env.KEY || 'qwerty'); var key = spritz.hash(stringKey, keyLengthInBytes); var byteArrMessage = spritz.stringToUtf8ByteArray(message); @@ -50,16 +50,20 @@ var encryptFile = function(message){ return JSON.stringify(cypher); }; +var wrapEncryptedData = function(encryptedData){ + return 'window.encryptedPlayerList = ' + encryptedData + ';'; +}; + gulp.task('encrypt-results', ['compile-results'], function(){ return gulp.src('api/*.clear.json') .pipe(modify({ fileModifier: function(file, content) { - return encryptFile(content); + return wrapEncryptedData(encryptFile(content)); } })) .pipe(rename(function(path){ path.basename = path.basename.replace(/\.clear$/i, ''); - path.extname = '.json.spritz'; + path.extname = '.spritz.js'; return path; })) .pipe(gulp.dest('./api')); @@ -75,7 +79,7 @@ gulp.task('template-prod', function () { gulp.task('template-dev', function () { return gulp.src('index.tmpl.html') .pipe(rename("index.html")) - .pipe(template({production: false, salt: '', playerListLocation: 'api/players.json.spritz'})) + .pipe(template({production: false, salt: 'salt', playerListLocation: 'api/players.spritz.js'})) .pipe(gulp.dest('.')); }); @@ -122,7 +126,6 @@ gulp.task('webserver', function(){ })); }); - gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){ gulp.watch('./scss/*.scss', ['sass']); gulp.watch('*.tmpl.html', ['template-dev']); diff --git a/index.tmpl.html b/index.tmpl.html index ae63481..29b95aa 100644 --- a/index.tmpl.html +++ b/index.tmpl.html @@ -12,8 +12,8 @@
+ <%if(production){ %> <% }else{ %> diff --git a/script/views/playersPage.js b/script/views/playersPage.js index 459cd4e..6ee8393 100644 --- a/script/views/playersPage.js +++ b/script/views/playersPage.js @@ -90,12 +90,24 @@ define(['m', '_', 'spritz', 'teams'], function (m, _ , spritz, teams) { return JSON.parse(spritz.utf8ByteArrayToString(decryptedMessage)); }; + playersTable.getEncryptedPlayerList = function(){ + var deferred = m.deferred(); + var interval = setInterval(function() { + if(!_.isEmpty(window.encryptedPlayerList)){ + clearInterval(interval); + deferred.resolve(window.encryptedPlayerList); + m.redraw(); + } + }, 333); + return deferred.promise; + }; + playersTable.controller = function(model){ var players = m.prop([]); var ctrl = {}; ctrl.model = model; - ctrl.players = m.request({method: "GET", url: window.playerListLocation}) + ctrl.players = playersTable.getEncryptedPlayerList() .then(playersTable.decryptPlayerList) .then(players); ctrl.sortPlayers = function(){