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 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

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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

View file

@ -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) => {

View file

@ -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

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 { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js');

View file

@ -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);
});
});

View file

@ -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) => {

View file

@ -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

View file

@ -20,12 +20,12 @@
<code>https://spee.ch/:name/:claim_id.ext</code>
<ul>
<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>
<code>https://spee.ch/:name/:claim_id</code>
<ul>
<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>
<code>https://spee.ch/:name/all</code>
<ul>

View file

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