Skip to content

Commit

Permalink
Use dynamodb to store featured picture per picset as well as all the …
Browse files Browse the repository at this point in the history
…pics with face information.
  • Loading branch information
rgfindl committed Dec 13, 2016
1 parent 509b36f commit c8cb66c
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea
node_modules
photos
_site
.sass-cache
npm-debug.log
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
60 changes: 38 additions & 22 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
};
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions util/get-dynamodb-picset-images.js
Original file line number Diff line number Diff line change
@@ -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));
});
File renamed without changes.
35 changes: 35 additions & 0 deletions util/seed-dynamodb-picset-images.js
Original file line number Diff line number Diff line change
@@ -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');
});

0 comments on commit c8cb66c

Please sign in to comment.