fixed the shorturl route

This commit is contained in:
bill bittner 2017-08-02 17:13:02 -07:00
parent 657dd62e5b
commit e8a89ca795
16 changed files with 31 additions and 26 deletions

View file

@ -1,7 +1,7 @@
const logger = require('winston'); const logger = require('winston');
const db = require('../models'); const db = require('../models');
const lbryApi = require('../helpers/libraries/lbryApi.js'); const lbryApi = require('../helpers/lbryApi.js');
const publishHelpers = require('../helpers/libraries/publishHelpers.js'); const publishHelpers = require('../helpers/publishHelpers.js');
function upsert (Model, values, condition) { function upsert (Model, values, condition) {
return Model return Model

View file

@ -1,9 +1,9 @@
const lbryApi = require('../helpers/libraries/lbryApi.js'); const lbryApi = require('../helpers/lbryApi.js');
const db = require('../models'); const db = require('../models');
const logger = require('winston'); const logger = require('winston');
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.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) { // function checkForLocalAssetByShortUrl (shortUrl, name) {
// } // }
@ -91,10 +91,10 @@ function getAssetByClaimId (fullClaimId, name) {
module.exports = { module.exports = {
getAssetByChannel (channelName, name) { getAssetByChannel (channelName, name) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// temporarily throw error
reject(new Error('channel names are not currently supported'));
// get the claim id // get the claim id
// get teh asset by claim Id // get teh asset by claim Id
}); });
}, },
getAssetByShortUrl: function (shortUrl, name) { getAssetByShortUrl: function (shortUrl, name) {

View file

@ -1,9 +1,9 @@
const lbryApi = require('../helpers/libraries/lbryApi.js'); const lbryApi = require('../helpers/lbryApi.js');
const db = require('../models'); const db = require('../models');
const logger = require('winston'); const logger = require('winston');
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
const serveHelpers = require('../helpers/libraries/serveHelpers.js'); const serveHelpers = require('../helpers/serveHelpers.js');
module.exports = { module.exports = {
showClaimByName (claimName) { showClaimByName (claimName) {

View file

@ -1,5 +1,5 @@
const logger = require('winston'); const logger = require('winston');
const { postToStats } = require('../../controllers/statsController.js'); const { postToStats } = require('../controllers/statsController.js');
module.exports = { module.exports = {
handleRequestError (action, originalUrl, ip, error, res) { handleRequestError (action, originalUrl, ip, error, res) {

View file

@ -1,5 +1,5 @@
const isFreePublicClaim = require('./isFreePublicClaim.js'); const isFreePublicClaim = require('./isFreePublicClaim.js');
const lbryApi = require('../libraries/lbryApi.js'); const lbryApi = require('../lbryApi.js');
const logger = require('winston'); const logger = require('winston');
function filterForFreePublicClaims (claimsListArray) { function filterForFreePublicClaims (claimsListArray) {

View file

@ -1,8 +1,10 @@
const logger = require('winston'); const logger = require('winston');
const db = require('../../models'); const db = require('../models');
const lbryApi = require('./lbryApi'); const lbryApi = require('./lbryApi');
function determineShortUrl (claimId, claimList) { function determineShortUrl (claimId, claimList) {
console.log('claimid =', claimId);
console.log('claimlist = ', claimList);
logger.debug('determining short url based on claim id and claim list'); 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 const thisClaim = claimList.filter(claim => { // find this claim in the list & store it
return claim.claim_id === claimId; return claim.claim_id === claimId;
@ -10,6 +12,7 @@ function determineShortUrl (claimId, claimList) {
claimList = claimList.filter(claim => { // remove this claim from the claim list claimList = claimList.filter(claim => { // remove this claim from the claim list
return claim.claim_id !== claimId; 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 if (claimList.length === 0) { // if there are no other claims, return the first letter of the claim id
return claimId.substring(0, 1); return claimId.substring(0, 1);
} else { } else {
@ -133,8 +136,9 @@ module.exports = {
}); });
}); });
}, },
getShortUrlFromClaimId (name, claimId) { getShortUrlFromClaimId (claimId, name) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log('getting short url');
// get a list of all the claims // get a list of all the claims
lbryApi.getClaimsList(name) lbryApi.getClaimsList(name)
// find the smallest possible unique url for this claim // find the smallest possible unique url for this claim

View file

@ -2,9 +2,9 @@ const logger = require('winston');
const multipart = require('connect-multiparty'); const multipart = require('connect-multiparty');
const multipartMiddleware = multipart(); const multipartMiddleware = multipart();
const publishController = require('../controllers/publishController.js'); const publishController = require('../controllers/publishController.js');
const lbryApi = require('../helpers/libraries/lbryApi.js'); const lbryApi = require('../helpers/lbryApi.js');
const { createPublishParams, validateFile } = require('../helpers/libraries/publishHelpers.js'); const { createPublishParams, validateFile } = require('../helpers/publishHelpers.js');
const errorHandlers = require('../helpers/libraries/errorHandlers.js'); const errorHandlers = require('../helpers/errorHandlers.js');
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
module.exports = (app, hostedContentPath) => { module.exports = (app, hostedContentPath) => {

View file

@ -1,5 +1,5 @@
const { postToStats, getTrendingClaims } = require('../controllers/statsController.js'); const { postToStats, getTrendingClaims } = require('../controllers/statsController.js');
const errorHandlers = require('../helpers/libraries/errorHandlers.js'); const errorHandlers = require('../helpers/errorHandlers.js');
module.exports = app => { module.exports = app => {
// route for the home page // route for the home page

View file

@ -1,4 +1,4 @@
const errorHandlers = require('../helpers/libraries/errorHandlers.js'); const errorHandlers = require('../helpers/errorHandlers.js');
const { showAllClaims } = require('../controllers/showController.js'); const { showAllClaims } = require('../controllers/showController.js');
const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js'); const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js');

View file

@ -1,8 +1,8 @@
const logger = require('winston'); 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 { getAssetByChannel, getAssetByShortUrl, getAssetByClaimId } = require('../controllers/serveController.js');
const { postToStats } = require('../controllers/statsController.js'); const { postToStats } = require('../controllers/statsController.js');
const { handleRequestError } = require('../helpers/libraries/errorHandlers.js'); const { handleRequestError } = require('../helpers/errorHandlers.js');
const SERVE = 'SERVE'; const SERVE = 'SERVE';
const SHOW = 'SHOW'; const SHOW = 'SHOW';
@ -116,6 +116,7 @@ module.exports = (app) => {
// if asset was retrieved from lbrynet, create db record // if asset was retrieved from lbrynet, create db record
}) })
.catch(error => { .catch(error => {
console.log('...error was caught');
handleRequestError('serve', originalUrl, ip, error, res); handleRequestError('serve', originalUrl, ip, error, res);
}); });
}); });

View file

@ -1,7 +1,7 @@
const logger = require('winston'); const logger = require('winston');
const publishController = require('../controllers/publishController.js'); const publishController = require('../controllers/publishController.js');
const publishHelpers = require('../helpers/libraries/publishHelpers.js'); const publishHelpers = require('../helpers/publishHelpers.js');
const errorHandlers = require('../helpers/libraries/errorHandlers.js'); const errorHandlers = require('../helpers/errorHandlers.js');
const { postToStats } = require('../controllers/statsController.js'); const { postToStats } = require('../controllers/statsController.js');
module.exports = (app, siofu, hostedContentPath) => { module.exports = (app, siofu, hostedContentPath) => {

View file

@ -6,7 +6,7 @@ const expressHandlebars = require('express-handlebars');
const Handlebars = require('handlebars'); const Handlebars = require('handlebars');
const config = require('config'); const config = require('config');
const logger = require('winston'); const logger = require('winston');
const { getDownloadDirectory } = require('./helpers/libraries/lbryApi'); const { getDownloadDirectory } = require('./helpers/lbryApi');
const PORT = 3000; // set port const PORT = 3000; // set port
const app = express(); // create an Express application const app = express(); // create an Express application

View file

@ -20,12 +20,12 @@
<code>https://spee.ch/:name/:claim_id.ext</code> <code>https://spee.ch/:name/:claim_id.ext</code>
<ul> <ul>
<li >Serves a specific image or video file directly</li> <li >Serves a specific image or video file directly</li>
<li >E.g. <a href="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg</a></li> <li >E.g. <a href="/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg</a></li>
</ul> </ul>
<code>https://spee.ch/:name/:claim_id</code> <code>https://spee.ch/:name/:claim_id</code>
<ul> <ul>
<li >Serves an HTML page with this specific claim and additional details</li> <li >Serves an HTML page with this specific claim and additional details</li>
<li >E.g. <a href="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0</a></li> <li >E.g. <a href="/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0</a></li>
</ul> </ul>
<code>https://spee.ch/:name/all</code> <code>https://spee.ch/:name/all</code>
<ul> <ul>

View file

@ -5,8 +5,8 @@
<div id="examples-detail" hidden="true"> <div id="examples-detail" hidden="true">
<div class="example"> <div class="example">
<h4>Use spee.ch to embed a specific image:</h4> <h4>Use spee.ch to embed a specific image:</h4>
<a href="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg"><img class="example-image" src="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg"/></a> <a href="/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg"><img class="example-image" src="/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg"/></a>
<div class="example-code">&lt;img src="https://spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0.jpg"/&gt;</div> <div class="example-code">&lt;img src="https://spee.ch/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg"/&gt;</div>
</div> </div>
<div class="example"> <div class="example">
<h4>Use spee.ch to serve the top free image at a claim:</h4> <h4>Use spee.ch to serve the top free image at a claim:</h4>