From fac77b2524791d560485c5b81493446f6f06bd81 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 15:22:29 -0700 Subject: [PATCH 1/7] updated back end to send availability and message --- .../claim/availability/checkClaimAvailability.js | 5 +---- server/controllers/api/claim/availability/index.js | 14 ++++++++++++-- server/controllers/api/claim/data/index.js | 10 ++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/controllers/api/claim/availability/checkClaimAvailability.js b/server/controllers/api/claim/availability/checkClaimAvailability.js index c4f4501a..9440fa86 100644 --- a/server/controllers/api/claim/availability/checkClaimAvailability.js +++ b/server/controllers/api/claim/availability/checkClaimAvailability.js @@ -18,10 +18,7 @@ const claimAvailability = (name) => { }, }) .then(result => { - if (result.length >= 1) { - throw new Error('That claim is already in use'); - } - return name; + return (result.length <= 0); }) .catch(error => { throw error; diff --git a/server/controllers/api/claim/availability/index.js b/server/controllers/api/claim/availability/index.js index 1583cb26..210e6033 100644 --- a/server/controllers/api/claim/availability/index.js +++ b/server/controllers/api/claim/availability/index.js @@ -11,8 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => { const gaStartTime = Date.now(); checkClaimAvailability(name) - .then(result => { - res.status(200).json(result); + .then(isAvailable => { + let responseObject = { + success: true, + data: isAvailable, + }; + if (isAvailable) { + responseObject['message'] = `That claim name is available` + } else { + responseObject['message'] = `That name is already in use` + } + console.log('response object', responseObject); + res.status(200).json(responseObject); sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); }) .catch(error => { diff --git a/server/controllers/api/claim/data/index.js b/server/controllers/api/claim/data/index.js index 49361d71..250e9849 100644 --- a/server/controllers/api/claim/data/index.js +++ b/server/controllers/api/claim/data/index.js @@ -14,9 +14,15 @@ const claimData = ({ ip, originalUrl, body, params }, res) => { db.Claim.resolveClaim(claimName, claimId) .then(claimInfo => { if (!claimInfo) { - return res.status(404).json({success: false, message: 'No claim could be found'}); + return res.status(404).json({ + success: false, + message: 'No claim could be found' + }); } - res.status(200).json({success: true, data: claimInfo}); + res.status(200).json({ + success: true, + data: claimInfo + }); }) .catch(error => { handleErrorResponse(originalUrl, ip, error, res); -- 2.45.2 From 3935fb1af03d2010b664756ebd56bb6c989341ae Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 15:25:44 -0700 Subject: [PATCH 2/7] removed console log --- server/controllers/api/claim/availability/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/controllers/api/claim/availability/index.js b/server/controllers/api/claim/availability/index.js index 210e6033..6c14c00a 100644 --- a/server/controllers/api/claim/availability/index.js +++ b/server/controllers/api/claim/availability/index.js @@ -21,7 +21,6 @@ const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => { } else { responseObject['message'] = `That name is already in use` } - console.log('response object', responseObject); res.status(200).json(responseObject); sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); }) -- 2.45.2 From 8b808b2c109ec5d623b90b8578c4b3da1ebfdca8 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 15:47:58 -0700 Subject: [PATCH 3/7] updated channel availability route --- .../availability/checkChannelAvailability.js | 9 ++++----- .../controllers/api/channel/availability/index.js | 15 ++++++++++++--- .../claim/availability/checkClaimAvailability.js | 2 +- .../controllers/api/claim/availability/index.js | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server/controllers/api/channel/availability/checkChannelAvailability.js b/server/controllers/api/channel/availability/checkChannelAvailability.js index 3c5d78b5..3261c63f 100644 --- a/server/controllers/api/channel/availability/checkChannelAvailability.js +++ b/server/controllers/api/channel/availability/checkChannelAvailability.js @@ -3,13 +3,12 @@ const db = require('../../../../models'); const checkChannelAvailability = (name) => { return db.Channel .findAll({ - where: { channelName: name }, + where: { + channelName: name, + }, }) .then(result => { - if (result.length >= 1) { - throw new Error('That channel has already been claimed'); - } - return name; + return (result.length <= 0); }) .catch(error => { throw error; diff --git a/server/controllers/api/channel/availability/index.js b/server/controllers/api/channel/availability/index.js index ae2a3807..e3b29ccb 100644 --- a/server/controllers/api/channel/availability/index.js +++ b/server/controllers/api/channel/availability/index.js @@ -11,9 +11,18 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { const gaStartTime = Date.now(); checkChannelAvailability(name) - .then(availableName => { - res.status(200).json(availableName); - sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); + .then(isAvailable => { + let responseObject = { + success: true, + data: isAvailable, + }; + if (isAvailable) { + responseObject['message'] = `That channel name is available` + } else { + responseObject['message'] = `That channel is already in use` + } + res.status(200).json(responseObject); + sendGATimingEvent('end-to-end', 'channel name availability', name, gaStartTime, Date.now()); }) .catch(error => { handleErrorResponse(originalUrl, ip, error, res); diff --git a/server/controllers/api/claim/availability/checkClaimAvailability.js b/server/controllers/api/claim/availability/checkClaimAvailability.js index 9440fa86..68c31056 100644 --- a/server/controllers/api/claim/availability/checkClaimAvailability.js +++ b/server/controllers/api/claim/availability/checkClaimAvailability.js @@ -1,4 +1,4 @@ -const db = require('../../../../models/index'); +const db = require('../../../../models'); const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../../../../config/siteConfig.js'); const Sequelize = require('sequelize'); const Op = Sequelize.Op; diff --git a/server/controllers/api/claim/availability/index.js b/server/controllers/api/claim/availability/index.js index 6c14c00a..da982e8f 100644 --- a/server/controllers/api/claim/availability/index.js +++ b/server/controllers/api/claim/availability/index.js @@ -19,7 +19,7 @@ const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => { if (isAvailable) { responseObject['message'] = `That claim name is available` } else { - responseObject['message'] = `That name is already in use` + responseObject['message'] = `That url is already in use` } res.status(200).json(responseObject); sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now()); -- 2.45.2 From 9a7fdf4834747bd5e68df0c9f53a8b2650ecfaa7 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 20:32:54 -0700 Subject: [PATCH 4/7] updated route to add the @ for channels --- server/controllers/api/channel/availability/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/controllers/api/channel/availability/index.js b/server/controllers/api/channel/availability/index.js index e3b29ccb..eb4a0c53 100644 --- a/server/controllers/api/channel/availability/index.js +++ b/server/controllers/api/channel/availability/index.js @@ -10,6 +10,7 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { const gaStartTime = Date.now(); + let name = `@${name}`; checkChannelAvailability(name) .then(isAvailable => { let responseObject = { @@ -17,9 +18,9 @@ const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { data: isAvailable, }; if (isAvailable) { - responseObject['message'] = `That channel name is available` + responseObject['message'] = `${name} is available` } else { - responseObject['message'] = `That channel is already in use` + responseObject['message'] = `${name} is already in use` } res.status(200).json(responseObject); sendGATimingEvent('end-to-end', 'channel name availability', name, gaStartTime, Date.now()); -- 2.45.2 From 52f2416d889d51210bcd42c0976cd57626d06928 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 May 2018 22:51:01 -0700 Subject: [PATCH 5/7] added claim availability check for channels via saga --- server/controllers/api/channel/availability/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/controllers/api/channel/availability/index.js b/server/controllers/api/channel/availability/index.js index eb4a0c53..dace8e01 100644 --- a/server/controllers/api/channel/availability/index.js +++ b/server/controllers/api/channel/availability/index.js @@ -8,9 +8,16 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); */ +function addAtSymbolIfNecessary (name) { + if (name.substring(0,1) !== '@') { + return `@${name}`; + } + return name; +} + const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => { const gaStartTime = Date.now(); - let name = `@${name}`; + name = addAtSymbolIfNecessary(name); checkChannelAvailability(name) .then(isAvailable => { let responseObject = { -- 2.45.2 From d817ab02b00172e78b10fcab47b6bef1024579e1 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 4 May 2018 10:11:53 -0700 Subject: [PATCH 6/7] updated auth routes for login check and logout --- server/controllers/auth/logout/index.js | 6 +++++- server/controllers/auth/user/index.js | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/controllers/auth/logout/index.js b/server/controllers/auth/logout/index.js index 13d945b1..e79ee7c0 100644 --- a/server/controllers/auth/logout/index.js +++ b/server/controllers/auth/logout/index.js @@ -1,6 +1,10 @@ const logout = (req, res) => { req.logout(); - res.status(200).json({success: true, message: 'you successfully logged out'}); + const responseObject = { + success: true, + message: 'you successfully logged out' + }; + res.status(200).json(responseObject); }; module.exports = logout; diff --git a/server/controllers/auth/user/index.js b/server/controllers/auth/user/index.js index 9e776bbd..7cb1bdd0 100644 --- a/server/controllers/auth/user/index.js +++ b/server/controllers/auth/user/index.js @@ -1,9 +1,9 @@ const user = (req, res) => { - if (req.user) { - res.status(200).json({success: true, data: req.user}); - } else { - res.status(401).json({success: false, message: 'user is not logged in'}); - } + const responseObject = { + success: true, + data: req.user, + }; + res.status(200).json(responseObject); }; module.exports = user; -- 2.45.2 From 7044a09cd6ac2e8cbde4c0b0faed3ab3c1d8f5a0 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 4 May 2018 11:36:09 -0700 Subject: [PATCH 7/7] added error chck for file sending --- server/controllers/assets/utils/serveFile.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/controllers/assets/utils/serveFile.js b/server/controllers/assets/utils/serveFile.js index ab3c167a..aa0f2e34 100644 --- a/server/controllers/assets/utils/serveFile.js +++ b/server/controllers/assets/utils/serveFile.js @@ -8,7 +8,12 @@ const serveFile = ({ filePath, fileType }, res) => { 'Content-Type' : fileType || 'image/jpeg', }, }; - res.status(200).sendFile(filePath, sendFileOptions); + res.status(200).sendFile(filePath, sendFileOptions, (error) => { + if (error) { + logger.warn(error); + res.status(404).send(); + } + }); }; module.exports = serveFile; -- 2.45.2