diff --git a/.gitignore b/.gitignore index 580f57a..4de1b73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .idea node_modules photos -_site -.sass-cache \ No newline at end of file +npm-debug.log \ No newline at end of file diff --git a/README.md b/README.md index 153d0e4..f5fd4ef 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,30 @@ # finpics Use AWS Rekognition to provide a faces search of finpics.com +## DynamoDB +### pics table +* primaykey (Primary Key) +* sortKey (Sort Key) +* ... Rekognition IndexFaces response + +*Picsets* +* primaykey: '/' (Primary Key) +* sortkey: '014_newportboston' (Sort Key) +* pic: 'Newport_pic_3.jpg' + +*Pics* +* primaykey: '014_newportboston' (Primary Key) +* sortkey: 'Newport_pic_3.jpg' (Sort Key) +* ... Rekognition IndexFaces response + ## Develop locally -npm install local-web-server -ws +npm run serve ## Deploy Install AWS CLI and configure profile credentials. ### Web Assets -aws s3 sync . s3://finpics.com --exclude "photos/*" --exclude ".gitignore" --exclude ".idea/*" --exclude ".git/*" --exclude "util/*" --exclude "node_modules/*" --exclude "package.json" --dryrun --storage-class REDUCED_REDUNDANCY --profile bluefin +npm run deploy-site ### Photos -aws s3 sync . s3://finpics-pics --exclude "*" --include "photos/*" --storage-class REDUCED_REDUNDANCY --profile bluefin +npm ren deploy-pics \ No newline at end of file diff --git a/js/app.js b/js/app.js index 7cba619..87058d3 100644 --- a/js/app.js +++ b/js/app.js @@ -91,23 +91,44 @@ function IndexController($scope, $http, $rootScope, config, cache) { } else { picsets = {}; $scope.loading = true; - $http.get('/picset-images.json').then(function (res) { - $scope.loading = false; - picsets = _.map(res.data, function(image) { - var dir = _.split(image, '/')[0]; - return { - path: dir, - name: _.join(_.drop(_.split(dir, '_')), ' '), - image: image - } - }); - $scope.picsets = picsets; - cache.store('picsets', picsets); - },function(res) { - console.log(JSON.stringify(res, null, 3)); - $scope.loading = false; - $scope.error = true; - $rootScope.$broadcast('mgalert', 'Please check errors.', 3); + + // Initialize the Amazon Cognito credentials provider + AWS.config.region = 'us-east-1'; // Region + AWS.config.credentials = new AWS.CognitoIdentityCredentials({ + IdentityPoolId: config.CognitoIdentityPoolId + }); + + var docClient = new AWS.DynamoDB.DocumentClient(); + var params = { + TableName: 'pics', + KeyConditionExpression: "primarykey = :primarykey", + ScanIndexForward: false, + ExpressionAttributeValues: { + ":primarykey": '/' + } + }; + console.log(JSON.stringify(params)); + docClient.query(params, function(err, data) { + if (err) { + $scope.loading = false; + $scope.error = true; + $rootScope.$broadcast('mgalert', 'Please check errors.', 3); + console.log(err); + } else { + $scope.loading = false; + picsets = _.map(data.Items, function(item) { + return { + path: item.sortkey, + name: _.join(_.drop(_.split(item.sortkey, '_')), ' '), + image: item.sortkey + '/thumbs/' + item.pic + } + }); + $scope.picsets = picsets; + cache.store('picsets', picsets); + } + if(!$scope.$$phase) { + $scope.$digest($scope); + } }); } }; @@ -123,11 +144,6 @@ function PicsetController($scope, $routeParams, $rootScope, config, cache) { } else { pics = []; $scope.loading = true; - // Initialize the Amazon Cognito credentials provider - AWS.config.region = 'us-east-1'; // Region - AWS.config.credentials = new AWS.CognitoIdentityCredentials({ - IdentityPoolId: config.CognitoIdentityPoolId - }); console.log('here'); var s3 = new AWS.S3(); var done = false; diff --git a/package.json b/package.json index 5e80f90..9b856a0 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "winston": "^2.3.0" }, "scripts": { - "test": "mocha" + "test": "mocha", + "deploy-site": "aws s3 sync . s3://finpics.com --exclude \"*\" --include \"index.html\" --include \"favicon.ico\" --include \"css/*\" --include \"images/*\" --include \"js/*\" --include \"partials/*\" --storage-class REDUCED_REDUNDANCY --profile bluefin", + "deploy-pics": "aws s3 sync . s3://finpics-pics --exclude \"*\" --include \"photos/*\" --storage-class REDUCED_REDUNDANCY --profile bluefin", + "serve": "ws" }, "repository": { "type": "git", diff --git a/util/get-dynamodb-picset-images.js b/util/get-dynamodb-picset-images.js new file mode 100644 index 0000000..b6ee5db --- /dev/null +++ b/util/get-dynamodb-picset-images.js @@ -0,0 +1,30 @@ +var winston = require('winston'); +var _ = require('lodash'); +var async = require('async'); +var AWS = require('aws-sdk'); + +var docClient = new AWS.DynamoDB.DocumentClient(); + +var functions = {}; + +// +// Handles DynamoDB calls. +// +functions.query = function(callback) { + var params = { + TableName: 'pics', + KeyConditionExpression: "primarykey = :primarykey", + ExpressionAttributeValues: { + ":primarykey": '/' + } + }; + winston.debug(JSON.stringify(params)); + docClient.query(params, function(err, data) { + if (err) winston.error(err); + callback(err, data); + }); +}; + +functions.query(function(err, data) { + winston.info(JSON.stringify(data, null, 3)); +}); \ No newline at end of file diff --git a/picset-images.json b/util/picset-images.json similarity index 100% rename from picset-images.json rename to util/picset-images.json diff --git a/util/seed-dynamodb-picset-images.js b/util/seed-dynamodb-picset-images.js new file mode 100644 index 0000000..2f384dd --- /dev/null +++ b/util/seed-dynamodb-picset-images.js @@ -0,0 +1,35 @@ +var winston = require('winston'); +var _ = require('lodash'); +var async = require('async'); +var AWS = require('aws-sdk'); + +var docClient = new AWS.DynamoDB.DocumentClient(); + +var functions = {}; + +// +// Handles DynamoDB calls. +// +functions.put = function(folder, image, callback) { + var params = { + TableName: 'pics', + Item: { + primarykey: '/', + sortkey: folder, + pic: image + } + }; + winston.debug(JSON.stringify(params)); + docClient.put(params, function(err, data) { + if (err) winston.error(err); + callback(err); + }); +}; + +var picset_images = require('./picset-images.json'); +async.eachSeries(picset_images, function(image, next){ + var split = _.split(image, '/'); + functions.put(split[0], split[2], next); +}, function(err) { + winston.info('Done'); +}); \ No newline at end of file