From a80cb558c67089dd2cd2096136aafe7f8922a33e Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Mon, 21 May 2018 08:36:26 -0400 Subject: [PATCH] begin writing routes/handlers for posting a sequence ref #10 --- adapters/sequence/index.js | 9 +++++---- connection.js | 4 ++++ handlers/index.js | 0 handlers/sequence/.post.js.swp | Bin 0 -> 12288 bytes handlers/sequence/helpers.js | 15 +++++++++++++++ handlers/sequence/index.js | 0 handlers/sequence/post.js | 12 ++++++++++++ routes/index.js | 5 +++++ routes/sequence/index.js | 5 +++++ routes/sequence/post.js | 15 +++++++++++++++ 10 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 connection.js create mode 100644 handlers/index.js create mode 100644 handlers/sequence/.post.js.swp create mode 100644 handlers/sequence/helpers.js create mode 100644 handlers/sequence/index.js create mode 100644 handlers/sequence/post.js create mode 100644 routes/index.js create mode 100644 routes/sequence/index.js create mode 100644 routes/sequence/post.js diff --git a/adapters/sequence/index.js b/adapters/sequence/index.js index 960cd79..d4ef8de 100644 --- a/adapters/sequence/index.js +++ b/adapters/sequence/index.js @@ -10,13 +10,14 @@ Promise = require('bluebird') /** * * @param {array} paths list of directory paths holding images to make sequences of - * @param {number} cutDist maximum distance allowed between two photos + * @param {number} maxCutDist maximum distance allowed between two photos + * @param {number} minCutDist minimum distance allowed between two photos * @param {cutTime} cutTime maximum time between two images * @param {cutSize} cutSize maximum size of a sequence. * @return {array} array of sequence configuration objects */ -module.exports = (paths, cutDist, cutTime, cutSize) => { +module.exports = (paths, minCutDist, maxCutDist, cutTime, cutSize) => { return new Promise((resolve, reject) => { Promise.map(paths, async (p) => { const images = await fs.readdir(p); @@ -25,8 +26,8 @@ module.exports = (paths, cutDist, cutTime, cutSize) => { .then(async (images) => { try { const params = { - maxDist: cutDist || 300, - minDist: 1, + maxDist: maxCutDist || 300, + minDist: minCutDist || 0.5, maxDetla: cutTime || 120, size: cutSize || 0 }, diff --git a/connection.js b/connection.js new file mode 100644 index 0000000..62e1dbb --- /dev/null +++ b/connection.js @@ -0,0 +1,4 @@ +'use strict'; + +const connection = require('./knexfile')[process.env.NODE_ENV || 'development'] +module.exports = require('knex')(connection); diff --git a/handlers/index.js b/handlers/index.js new file mode 100644 index 0000000..e69de29 diff --git a/handlers/sequence/.post.js.swp b/handlers/sequence/.post.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..1ae60cccc1bbec7710a8707480a6dfa6c3a1e436 GIT binary patch literal 12288 zcmeI2zi-qq6vutX!VLvP7bFmJVYr->b4s}aQgsZd3>grWP(h+%a1!_8Hi?7n96h1J z2!8`3EB^^=g~ZmG$0y2gI!DWo!w2*>8xXiI5c2a~ zd+W^N$M%m~gyekBS^s*0Uw=c3SQ@E{{_5(=^6^_gEt0!ZK_1S-4Tzq7D;bLGbL>%4w#i7sB;JjqV< zK>|ns2_OL^fCP{L5s)$dd&^4nXez|K|7q_w$5&108@qfZl@MfKt#1v<@1Au7X;iujdH) z0(uX63hIKEKvzJQL1#gqA;+gC*C}L$B_jbOfCP{L5Pr|&+L@o-;Eu7N!gw{&4To}VgqPGTHXv}S#(%DLnz9bN1zXwA-HUXnb zW{J>Vb3i*xd|DZy-Q3uWi`eP#7hGDpp;a!8VB1RH=W*(7$pYN%qxyiiPiN0z4waZ^ zKK1GhJvzJ#W&A13!)QmumhFm(IjqI>e9FzFi0PpzOzJqUAWExBCUiKR#shCwCRnHS zgI%+dYn~hCEUt%G6~-R*Rl7_w#S@=&te!xHxk{=`FtJxEZ4J28C1{_fP4XIo+Yfz9 zExc}&RU(o)=|UA`md8~$9?UyAOE4ZdpP5S%%`Y<+zzr(}uz>e^ { + const sequence = sequences[sequenceId]; + + Promise.map(sequence, image => { + return Object + .values(image) + .concat([sequenceId, userId]) + .join(','); + }) + .then((values) => `the insert`) + .catch((error) => { throw error }); + +} diff --git a/handlers/sequence/index.js b/handlers/sequence/index.js new file mode 100644 index 0000000..e69de29 diff --git a/handlers/sequence/post.js b/handlers/sequence/post.js new file mode 100644 index 0000000..c743da3 --- /dev/null +++ b/handlers/sequence/post.js @@ -0,0 +1,12 @@ +'use strict'; + +const Boom = require('boom'); +const db = require('../../connection'); +const uuidv4 = require('uuid/v4'); + +module.exports = async (r, h) => { + try { + } catch (error) { + return Boom.badImplementation(error.message); + } +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..a63fc2e --- /dev/null +++ b/routes/index.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = [ + require('./sequence').post +] diff --git a/routes/sequence/index.js b/routes/sequence/index.js new file mode 100644 index 0000000..c770af0 --- /dev/null +++ b/routes/sequence/index.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = { + post: require('./post') +} diff --git a/routes/sequence/post.js b/routes/sequence/post.js new file mode 100644 index 0000000..e8f6f7f --- /dev/null +++ b/routes/sequence/post.js @@ -0,0 +1,15 @@ +'use strict'; + +const sequencesSchema = require('../../schema/sequences.js'); + +module.exports = { + method: 'POST', + path: '/sequence', + config: { + handler: require('../../handlers/sequence').get, + validate: { + payload: sequencesSchema, + failAction: async (r, h, err) => err + } + } +}