changed 'short url' to 'short id'

This commit is contained in:
bill bittner 2017-08-10 10:49:19 -07:00
parent 965ae1c360
commit 4b3d6f72cc
4 changed files with 30 additions and 29 deletions

View file

@ -89,10 +89,10 @@ module.exports = {
// get teh asset by claim Id
});
},
getAssetByShortUrl: function (shortUrl, name) {
getAssetByShortId: function (shortId, name) {
return new Promise((resolve, reject) => {
// get the full claimId
serveHelpers.getClaimIdFromShortUrl(shortUrl, name)
serveHelpers.getFullClaimIdFromShortId(shortId, name)
// get the asset by the claimId
.then(claimId => {
resolve(getAssetByClaimId(claimId, name));

View file

@ -2,7 +2,7 @@ const logger = require('winston');
const db = require('../models');
const lbryApi = require('./lbryApi');
function determineShortUrl (claimId, height, claimList) {
function determineShortClaimId (claimId, height, claimList) {
logger.debug('determining short url based on claim id and claim list');
// remove this claim from the claim list, if it exists
claimList = claimList.filter(claim => {
@ -37,12 +37,12 @@ function determineShortUrl (claimId, height, claimList) {
}
}
function checkLocalDbForClaims (name, shortUrl) {
function checkLocalDbForClaims (name, shortId) {
return db.File
.findAll({
where: {
name,
claimId: { $like: `${shortUrl}%` },
claimId: { $like: `${shortId}%` },
},
})
.then(records => {
@ -102,7 +102,7 @@ module.exports = {
const openGraphInfo = createOpenGraphInfo(fileInfo);
res.status(200).render('showLite', { layout: 'show', fileInfo, openGraphInfo });
},
getClaimIdFromShortUrl (shortUrl, name) {
getFullClaimIdFromShortId (shortId, name) {
return new Promise((resolve, reject) => {
logger.debug('getting claim_id from short url');
// use the daemon to check for claims list
@ -111,7 +111,7 @@ module.exports = {
logger.debug('Number of claims from getClaimsList:', claims.length);
// if no claims were found, check locally for possible claims
if (claims.length === 0) {
return checkLocalDbForClaims(name, shortUrl);
return checkLocalDbForClaims(name, shortId);
} else {
return claims;
}
@ -119,7 +119,7 @@ module.exports = {
// handle the claims list
.then(claims => {
logger.debug('Claims ready for filtering');
const regex = new RegExp(`^${shortUrl}`);
const regex = new RegExp(`^${shortId}`);
const filteredClaimsList = claims.filter(claim => {
return regex.test(claim.claim_id);
});
@ -143,15 +143,16 @@ module.exports = {
});
});
},
getShortUrlFromClaimId (claimId, height, name) {
getShortIdFromClaimId (claimId, height, name) {
return new Promise((resolve, reject) => {
logger.debug('finding short url from claim_id');
logger.debug('finding short claim id from full claim id');
// get a list of all the claims
lbryApi.getClaimsList(name)
// find the smallest possible unique url for this claim
.then(({ claims }) => {
const shortUrl = determineShortUrl(claimId, height, claims);
resolve(shortUrl);
const shortId = determineShortClaimId(claimId, height, claims);
logger.debug('short claim id ===', shortId);
resolve(shortId);
})
.catch(error => {
reject(error);

View file

@ -1,6 +1,6 @@
const logger = require('winston');
const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/serveHelpers.js');
const { getAssetByChannel, getAssetByShortUrl, getAssetByClaimId, getAssetByName } = require('../controllers/serveController.js');
const { serveFile, showFile, showFileLite, getShortIdFromClaimId } = require('../helpers/serveHelpers.js');
const { getAssetByChannel, getAssetByShortId, getAssetByClaimId, getAssetByName } = require('../controllers/serveController.js');
const { handleRequestError } = require('../helpers/errorHandlers.js');
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
const SERVE = 'SERVE';
@ -11,12 +11,12 @@ const SHORTURL = 'SHORTURL';
const CLAIMID = 'CLAIMID';
const NAME = 'NAME';
function getAsset (claimType, channelName, shortUrl, fullClaimId, name) {
function getAsset (claimType, channelName, shortId, fullClaimId, name) {
switch (claimType) {
case CHANNEL:
return getAssetByChannel(channelName, name);
case SHORTURL:
return getAssetByShortUrl(shortUrl, name);
return getAssetByShortId(shortId, name);
case CLAIMID:
return getAssetByClaimId(fullClaimId, name);
case NAME:
@ -41,9 +41,9 @@ function serveOrShowAsset (fileInfo, method, headers, originalUrl, ip, res) {
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
return fileInfo;
case SHOW:
return getShortUrlFromClaimId(fileInfo.claimId, fileInfo.height, fileInfo.name)
.then(shortUrl => {
fileInfo['shortUrl'] = shortUrl;
return getShortIdFromClaimId(fileInfo.claimId, fileInfo.height, fileInfo.name)
.then(shortId => {
fileInfo['shortId'] = shortId;
showFile(fileInfo, res);
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
return fileInfo;
@ -62,12 +62,12 @@ function isValidClaimId (claimId) {
return ((claimId.length === 40) && !/[^A-Za-z0-9]/g.test(claimId));
}
function isValidShortUrl (claimId) {
function isValidShortId (claimId) {
return claimId.length === 1; // really it should evaluate the short url itself
}
function isValidShortUrlOrClaimId (input) {
return (isValidClaimId(input) || isValidShortUrl(input));
function isValidShortIdOrClaimId (input) {
return (isValidClaimId(input) || isValidShortId(input));
}
module.exports = (app) => {
@ -77,7 +77,7 @@ module.exports = (app) => {
let name = params.name;
let claimType;
let channelName = null;
let shortUrl = null;
let shortId = null;
let fullClaimId = null;
let method;
let extension;
@ -101,7 +101,7 @@ module.exports = (app) => {
method = SHOW;
}
/* patch for backwards compatability with spee.ch/name/claim_id */
if (isValidShortUrlOrClaimId(name) && !isValidShortUrlOrClaimId(identifier)) {
if (isValidShortIdOrClaimId(name) && !isValidShortIdOrClaimId(identifier)) {
let tempName = name;
name = identifier;
identifier = tempName;
@ -119,8 +119,8 @@ module.exports = (app) => {
logger.debug('full claim id =', fullClaimId);
claimType = CLAIMID;
} else if (identifier.length < 40) {
shortUrl = identifier;
logger.debug('short url =', shortUrl);
shortId = identifier;
logger.debug('short claim id =', shortId);
claimType = SHORTURL;
} else {
logger.error('The URL provided could not be parsed');
@ -128,7 +128,7 @@ module.exports = (app) => {
return;
};
// 1. retrieve the asset and information
getAsset(claimType, channelName, shortUrl, fullClaimId, name)
getAsset(claimType, channelName, shortId, fullClaimId, name)
// 2. serve or show
.then(fileInfo => {
if (!fileInfo) {

View file

@ -15,11 +15,11 @@
</div>
{{!--short direct link to asset--}}
<div class="share-option">
<a href="/{{fileInfo.shortUrl}}/{{fileInfo.name}}{{fileInfo.fileExt}}">Permanent Short Link</a>
<a href="/{{fileInfo.shortId}}/{{fileInfo.name}}{{fileInfo.fileExt}}">Permanent Short Link</a>
(most convenient)
<div class="input-error" id="input-error-copy-short-link" hidden="true"></div>
<br/>
<input type="text" id="short-link" class="link" readonly spellcheck="false" value="https://spee.ch/{{fileInfo.shortUrl}}/{{fileInfo.name}}{{fileInfo.fileExt}}" onclick="select()"/>
<input type="text" id="short-link" class="link" readonly spellcheck="false" value="https://spee.ch/{{fileInfo.shortId}}/{{fileInfo.name}}{{fileInfo.fileExt}}" onclick="select()"/>
<button class="copy-button" data-elementtocopy="short-link" onclick="copyToClipboard(event)">copy</button>
</div>
{{!-- html text for embedding asset--}}