From e8a89ca79522c9b4252959c2856fa11123ad1d29 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 2 Aug 2017 17:13:02 -0700 Subject: [PATCH 01/12] fixed the shorturl route --- controllers/publishController.js | 4 ++-- controllers/serveController.js | 8 ++++---- controllers/showController.js | 4 ++-- helpers/{libraries => }/errorHandlers.js | 2 +- helpers/functions/getAllFreePublicClaims.js | 2 +- helpers/{libraries => }/lbryApi.js | 0 helpers/{libraries => }/publishHelpers.js | 0 helpers/{libraries => }/serveHelpers.js | 8 ++++++-- routes/api-routes.js | 6 +++--- routes/home-routes.js | 2 +- routes/page-routes.js | 2 +- routes/serve-routes.js | 5 +++-- routes/sockets-routes.js | 4 ++-- speech.js | 2 +- views/partials/documentation.handlebars | 4 ++-- views/partials/examples.handlebars | 4 ++-- 16 files changed, 31 insertions(+), 26 deletions(-) rename helpers/{libraries => }/errorHandlers.js (94%) rename helpers/{libraries => }/lbryApi.js (100%) rename helpers/{libraries => }/publishHelpers.js (100%) rename helpers/{libraries => }/serveHelpers.js (95%) diff --git a/controllers/publishController.js b/controllers/publishController.js index 06e5f0eb..13e67c72 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -1,7 +1,7 @@ const logger = require('winston'); const db = require('../models'); -const lbryApi = require('../helpers/libraries/lbryApi.js'); -const publishHelpers = require('../helpers/libraries/publishHelpers.js'); +const lbryApi = require('../helpers/lbryApi.js'); +const publishHelpers = require('../helpers/publishHelpers.js'); function upsert (Model, values, condition) { return Model diff --git a/controllers/serveController.js b/controllers/serveController.js index 6569be11..3e032d5b 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -1,9 +1,9 @@ -const lbryApi = require('../helpers/libraries/lbryApi.js'); +const lbryApi = require('../helpers/lbryApi.js'); const db = require('../models'); const logger = require('winston'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); -const serveHelpers = require('../helpers/libraries/serveHelpers.js'); +const serveHelpers = require('../helpers/serveHelpers.js'); // function checkForLocalAssetByShortUrl (shortUrl, name) { // } @@ -91,10 +91,10 @@ function getAssetByClaimId (fullClaimId, name) { module.exports = { getAssetByChannel (channelName, name) { return new Promise((resolve, reject) => { + // temporarily throw error + reject(new Error('channel names are not currently supported')); // get the claim id - // get teh asset by claim Id - }); }, getAssetByShortUrl: function (shortUrl, name) { diff --git a/controllers/showController.js b/controllers/showController.js index 78ef27bf..922fcdf7 100644 --- a/controllers/showController.js +++ b/controllers/showController.js @@ -1,9 +1,9 @@ -const lbryApi = require('../helpers/libraries/lbryApi.js'); +const lbryApi = require('../helpers/lbryApi.js'); const db = require('../models'); const logger = require('winston'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); -const serveHelpers = require('../helpers/libraries/serveHelpers.js'); +const serveHelpers = require('../helpers/serveHelpers.js'); module.exports = { showClaimByName (claimName) { diff --git a/helpers/libraries/errorHandlers.js b/helpers/errorHandlers.js similarity index 94% rename from helpers/libraries/errorHandlers.js rename to helpers/errorHandlers.js index 188a6757..0bf168e3 100644 --- a/helpers/libraries/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -1,5 +1,5 @@ const logger = require('winston'); -const { postToStats } = require('../../controllers/statsController.js'); +const { postToStats } = require('../controllers/statsController.js'); module.exports = { handleRequestError (action, originalUrl, ip, error, res) { diff --git a/helpers/functions/getAllFreePublicClaims.js b/helpers/functions/getAllFreePublicClaims.js index e5f6f8c7..120379fa 100644 --- a/helpers/functions/getAllFreePublicClaims.js +++ b/helpers/functions/getAllFreePublicClaims.js @@ -1,5 +1,5 @@ const isFreePublicClaim = require('./isFreePublicClaim.js'); -const lbryApi = require('../libraries/lbryApi.js'); +const lbryApi = require('../lbryApi.js'); const logger = require('winston'); function filterForFreePublicClaims (claimsListArray) { diff --git a/helpers/libraries/lbryApi.js b/helpers/lbryApi.js similarity index 100% rename from helpers/libraries/lbryApi.js rename to helpers/lbryApi.js diff --git a/helpers/libraries/publishHelpers.js b/helpers/publishHelpers.js similarity index 100% rename from helpers/libraries/publishHelpers.js rename to helpers/publishHelpers.js diff --git a/helpers/libraries/serveHelpers.js b/helpers/serveHelpers.js similarity index 95% rename from helpers/libraries/serveHelpers.js rename to helpers/serveHelpers.js index 9e80a55d..8b7bdc7c 100644 --- a/helpers/libraries/serveHelpers.js +++ b/helpers/serveHelpers.js @@ -1,8 +1,10 @@ const logger = require('winston'); -const db = require('../../models'); +const db = require('../models'); const lbryApi = require('./lbryApi'); function determineShortUrl (claimId, claimList) { + console.log('claimid =', claimId); + console.log('claimlist = ', claimList); logger.debug('determining short url based on claim id and claim list'); const thisClaim = claimList.filter(claim => { // find this claim in the list & store it return claim.claim_id === claimId; @@ -10,6 +12,7 @@ function determineShortUrl (claimId, claimList) { claimList = claimList.filter(claim => { // remove this claim from the claim list return claim.claim_id !== claimId; }); + console.log(claimList.length); if (claimList.length === 0) { // if there are no other claims, return the first letter of the claim id return claimId.substring(0, 1); } else { @@ -133,8 +136,9 @@ module.exports = { }); }); }, - getShortUrlFromClaimId (name, claimId) { + getShortUrlFromClaimId (claimId, name) { return new Promise((resolve, reject) => { + console.log('getting short url'); // get a list of all the claims lbryApi.getClaimsList(name) // find the smallest possible unique url for this claim diff --git a/routes/api-routes.js b/routes/api-routes.js index 01a27f85..c714a56b 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -2,9 +2,9 @@ const logger = require('winston'); const multipart = require('connect-multiparty'); const multipartMiddleware = multipart(); const publishController = require('../controllers/publishController.js'); -const lbryApi = require('../helpers/libraries/lbryApi.js'); -const { createPublishParams, validateFile } = require('../helpers/libraries/publishHelpers.js'); -const errorHandlers = require('../helpers/libraries/errorHandlers.js'); +const lbryApi = require('../helpers/lbryApi.js'); +const { createPublishParams, validateFile } = require('../helpers/publishHelpers.js'); +const errorHandlers = require('../helpers/errorHandlers.js'); const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); module.exports = (app, hostedContentPath) => { diff --git a/routes/home-routes.js b/routes/home-routes.js index 658e4711..4b74eaee 100644 --- a/routes/home-routes.js +++ b/routes/home-routes.js @@ -1,5 +1,5 @@ const { postToStats, getTrendingClaims } = require('../controllers/statsController.js'); -const errorHandlers = require('../helpers/libraries/errorHandlers.js'); +const errorHandlers = require('../helpers/errorHandlers.js'); module.exports = app => { // route for the home page diff --git a/routes/page-routes.js b/routes/page-routes.js index 7f571f97..9b14b814 100644 --- a/routes/page-routes.js +++ b/routes/page-routes.js @@ -1,4 +1,4 @@ -const errorHandlers = require('../helpers/libraries/errorHandlers.js'); +const errorHandlers = require('../helpers/errorHandlers.js'); const { showAllClaims } = require('../controllers/showController.js'); const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js'); diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 3eb86af0..e36e7d5a 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -1,8 +1,8 @@ const logger = require('winston'); -const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/libraries/serveHelpers.js'); +const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/serveHelpers.js'); const { getAssetByChannel, getAssetByShortUrl, getAssetByClaimId } = require('../controllers/serveController.js'); const { postToStats } = require('../controllers/statsController.js'); -const { handleRequestError } = require('../helpers/libraries/errorHandlers.js'); +const { handleRequestError } = require('../helpers/errorHandlers.js'); const SERVE = 'SERVE'; const SHOW = 'SHOW'; @@ -116,6 +116,7 @@ module.exports = (app) => { // if asset was retrieved from lbrynet, create db record }) .catch(error => { + console.log('...error was caught'); handleRequestError('serve', originalUrl, ip, error, res); }); }); diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index 86ad1f39..5df76845 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -1,7 +1,7 @@ const logger = require('winston'); const publishController = require('../controllers/publishController.js'); -const publishHelpers = require('../helpers/libraries/publishHelpers.js'); -const errorHandlers = require('../helpers/libraries/errorHandlers.js'); +const publishHelpers = require('../helpers/publishHelpers.js'); +const errorHandlers = require('../helpers/errorHandlers.js'); const { postToStats } = require('../controllers/statsController.js'); module.exports = (app, siofu, hostedContentPath) => { diff --git a/speech.js b/speech.js index f8dbc250..c042e8ea 100644 --- a/speech.js +++ b/speech.js @@ -6,7 +6,7 @@ const expressHandlebars = require('express-handlebars'); const Handlebars = require('handlebars'); const config = require('config'); const logger = require('winston'); -const { getDownloadDirectory } = require('./helpers/libraries/lbryApi'); +const { getDownloadDirectory } = require('./helpers/lbryApi'); const PORT = 3000; // set port const app = express(); // create an Express application diff --git a/views/partials/documentation.handlebars b/views/partials/documentation.handlebars index c1186a4e..4aba4ef0 100644 --- a/views/partials/documentation.handlebars +++ b/views/partials/documentation.handlebars @@ -20,12 +20,12 @@ https://spee.ch/:name/:claim_id.ext https://spee.ch/:name/:claim_id https://spee.ch/:name/all