From 65b5384330d346da29943576e55b348566ff9918 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 28 Sep 2017 11:42:29 -0700 Subject: [PATCH] added api routes for getting short ids --- controllers/serveController.js | 2 +- models/index.js | 2 +- routes/api-routes.js | 28 ++++++++++++++++++- views/partials/publishForm-Channel.handlebars | 3 ++ views/partials/publishForm-Url.handlebars | 3 +- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/controllers/serveController.js b/controllers/serveController.js index 95b9f77e..be7de126 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -150,7 +150,7 @@ module.exports = { // 2. get all claims for that channel .then(result => { longChannelId = result; - return db.getShortChannelIdFromLongChannelId(channelName, longChannelId); + return db.getShortChannelIdFromLongChannelId(longChannelId, channelName); }) // 3. get all Claim records for this channel .then(result => { diff --git a/models/index.js b/models/index.js index e87a147d..52bdcf63 100644 --- a/models/index.js +++ b/models/index.js @@ -190,7 +190,7 @@ db['getShortClaimIdFromLongClaimId'] = (claimId, claimName) => { }); }; -db['getShortChannelIdFromLongChannelId'] = (channelName, longChannelId) => { +db['getShortChannelIdFromLongChannelId'] = (longChannelId, channelName) => { return new Promise((resolve, reject) => { logger.debug('finding short channel id'); db diff --git a/routes/api-routes.js b/routes/api-routes.js index 5cc73480..28e614ef 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -1,6 +1,7 @@ const logger = require('winston'); const multipart = require('connect-multiparty'); const multipartMiddleware = multipart(); +const db = require('../models'); const { publish } = require('../controllers/publishController.js'); const { getClaimList, resolveUri } = require('../helpers/lbryApi.js'); const { createPublishParams, validateFile, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js'); @@ -69,7 +70,6 @@ module.exports = (app) => { errorHandlers.handleRequestError('publish', originalUrl, ip, error, res); }); }); - // route to run a publish request on the daemon app.post('/api/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl }, res) => { // google analytics @@ -104,9 +104,11 @@ module.exports = (app) => { } return createPublishParams(name, filePath, title, description, license, nsfw, channelName); }) + // create publish parameters object .then(publishParams => { return publish(publishParams, fileName, fileType); }) + // publish the asset .then(result => { postToStats('publish', originalUrl, ip, null, null, 'success'); res.status(200).json(result); @@ -115,4 +117,28 @@ module.exports = (app) => { logger.error('publish api error', error); }); }); + // route to get a short claim id from long claim Id + app.get('/api/shortClaimId/:longId/:name', ({ originalUrl, ip, params }, res) => { + // serve content + db.getShortClaimIdFromLongClaimId(params.longId, params.name) + .then(shortId => { + res.status(200).json(shortId); + }) + .catch(error => { + logger.error('api error getting short channel id', error); + res.status(400).json(error.message); + }); + }); + // route to get a short channel id from long channel Id + app.get('/api/shortChannelId/:longId/:name', ({ params }, res) => { + // serve content + db.getShortChannelIdFromLongChannelId(params.longId, params.name) + .then(shortId => { + res.status(200).json(shortId); + }) + .catch(error => { + logger.error('api error getting short channel id', error); + res.status(400).json(error.message); + }); + }); }; diff --git a/views/partials/publishForm-Channel.handlebars b/views/partials/publishForm-Channel.handlebars index 9b591548..cd9a0547 100644 --- a/views/partials/publishForm-Channel.handlebars +++ b/views/partials/publishForm-Channel.handlebars @@ -55,6 +55,9 @@ if (selectedOption === 'none'){ urlChannel.innerText = ''; } else { + // retrieve short url from db + + // update url text urlChannel.innerText = `${selectedOption}/`; } diff --git a/views/partials/publishForm-Url.handlebars b/views/partials/publishForm-Url.handlebars index 82b3e753..a916982d 100644 --- a/views/partials/publishForm-Url.handlebars +++ b/views/partials/publishForm-Url.handlebars @@ -10,4 +10,5 @@ - \ No newline at end of file + +