finished basic /shortUrl/claim route conversion
This commit is contained in:
parent
238f2af63f
commit
657dd62e5b
4 changed files with 123 additions and 321 deletions
|
@ -5,28 +5,11 @@ const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicCla
|
||||||
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/libraries/serveHelpers.js');
|
||||||
|
|
||||||
function checkForLocalAssetByShortUrl (channel, name) {
|
// function checkForLocalAssetByShortUrl (shortUrl, name) {
|
||||||
return new Promise((resolve, reject) => {
|
// }
|
||||||
db.File
|
|
||||||
.findOne({where: { name, channel }})
|
|
||||||
.then(result => {
|
|
||||||
if (result) {
|
|
||||||
resolve(result.dataValues);
|
|
||||||
} else {
|
|
||||||
resolve(null);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkForLocalAssetByChannel (channelName, name) {
|
// function checkForLocalAssetByChannel (channelName, name) {
|
||||||
return new Promise((resolve, reject) => {
|
// }
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkForLocalAssetByClaimId (claimId, name) {
|
function checkForLocalAssetByClaimId (claimId, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -57,37 +40,70 @@ function formatGetResultsToFileInfo ({ name, claim_id, outpoint, file_name, down
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
function getAssetByClaimId (fullClaimId, name) {
|
||||||
getAssetByChannel (channelName, name) {
|
return new Promise((resolve, reject) => {
|
||||||
return new Promise((resolve, reject) => {
|
// 1. check locally for claim
|
||||||
// check locally for claim
|
checkForLocalAssetByClaimId(fullClaimId, name)
|
||||||
checkForLocalAssetByChannel(channelName, name)
|
.then(dataValues => {
|
||||||
.then(result => {
|
// 2. if a result was found, resolve the result
|
||||||
// if not found locally, make a get request
|
if (dataValues) {
|
||||||
if (!result) {
|
logger.debug('found a local file for this claimId');
|
||||||
resolve();
|
// trigger an update check for the file
|
||||||
// if a result was found, resolve the result
|
/*
|
||||||
|
serveHelpers.updateFileIfNeeded(dataValues.name, dataValues.claimId, dataValues.outpoint, dataValues.height);
|
||||||
|
*/
|
||||||
|
// resolve promise
|
||||||
|
resolve(dataValues);
|
||||||
|
// 2. if not found locally, make a get request
|
||||||
|
} else {
|
||||||
|
logger.debug('no local file for this claimId');
|
||||||
|
// 3. resolve the claim
|
||||||
|
lbryApi.resolveUri(`${name}#${fullClaimId}`)
|
||||||
|
.then(resolveResult => {
|
||||||
|
// if the claim is free and public, then get it
|
||||||
|
if (resolveResult.claim && isFreePublicClaim(resolveResult.claim)) {
|
||||||
|
lbryApi.getClaim(`${name}#${fullClaimId}`)
|
||||||
|
.then(getResult => {
|
||||||
|
let fileInfo = formatGetResultsToFileInfo(getResult);
|
||||||
|
fileInfo['address'] = resolveResult.claim.address;
|
||||||
|
fileInfo['height'] = resolveResult.claim.height;
|
||||||
|
resolve(fileInfo);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
// if not, resolve with no claims
|
||||||
} else {
|
} else {
|
||||||
resolve(result);
|
resolve(null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAssetByChannel (channelName, name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// get the claim id
|
||||||
|
|
||||||
|
// get teh asset by claim Id
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getAssetByShortUrl (shortUrl, name) {
|
getAssetByShortUrl: function (shortUrl, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// check locally for claim
|
// get the full claimId
|
||||||
checkForLocalAssetByShortUrl(shortUrl, name)
|
serveHelpers.getClaimIdByShortUrl(shortUrl, name)
|
||||||
.then(result => {
|
// get the asset by the claimId
|
||||||
// if not found locally, make a get request
|
.then(claimId => {
|
||||||
if (!result) {
|
resolve(getAssetByClaimId(claimId, name));
|
||||||
resolve();
|
|
||||||
// if a result was found, resolve the result
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -95,49 +111,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getAssetByClaimId (fullClaimId, name) {
|
getAssetByClaimId (fullClaimId, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return getAssetByClaimId(fullClaimId, name);
|
||||||
// 1. check locally for claim
|
|
||||||
checkForLocalAssetByClaimId(fullClaimId, name)
|
|
||||||
.then(dataValues => {
|
|
||||||
// 2. if a result was found, resolve the result
|
|
||||||
if (dataValues) {
|
|
||||||
logger.debug('found a local file for this claimId');
|
|
||||||
// trigger an update check for the file
|
|
||||||
serveHelpers.updateFileIfNeeded(dataValues.name, dataValues.claimId, dataValues.outpoint, dataValues.height);
|
|
||||||
// resolve promise
|
|
||||||
resolve(dataValues);
|
|
||||||
// 2. if not found locally, make a get request
|
|
||||||
} else {
|
|
||||||
logger.debug('no local file for this claimId');
|
|
||||||
// 3. resolve the claim
|
|
||||||
lbryApi.resolveUri(`${name}#${fullClaimId}`)
|
|
||||||
.then(resolveResult => {
|
|
||||||
// if the claim is free and public, then get it
|
|
||||||
if (resolveResult.claim && isFreePublicClaim(resolveResult.claim)) {
|
|
||||||
lbryApi.getClaim(`${name}#${fullClaimId}`)
|
|
||||||
.then(getResult => {
|
|
||||||
let fileInfo = formatGetResultsToFileInfo(getResult);
|
|
||||||
fileInfo['address'] = resolveResult.claim.address;
|
|
||||||
fileInfo['height'] = resolveResult.claim.height;
|
|
||||||
resolve(fileInfo);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
// if not, resolve with no claims
|
|
||||||
} else {
|
|
||||||
resolve(null);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
serveClaimByName (claimName) {
|
serveClaimByName (claimName) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
|
@ -180,50 +154,4 @@ module.exports = {
|
||||||
});
|
});
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
|
|
||||||
serveClaimByShortUrl (name, shortUrl) {
|
|
||||||
const deferred = new Promise((resolve, reject) => {
|
|
||||||
let uri;
|
|
||||||
let claimId;
|
|
||||||
// 1. validate the claim id & retrieve the full claim id if needed
|
|
||||||
serveHelpers
|
|
||||||
.getClaimIdByShortUrl(name, shortUrl)
|
|
||||||
.then(result => {
|
|
||||||
// 2. check locally for the claim
|
|
||||||
uri = `${name}#${result}`;
|
|
||||||
claimId = result;
|
|
||||||
return db.File.findOne({ where: { name, claimId } });
|
|
||||||
})
|
|
||||||
.then(result => {
|
|
||||||
// 3. if a match is found locally, serve that claim
|
|
||||||
if (result) {
|
|
||||||
// return the data for the file to be served
|
|
||||||
resolve(result.dataValues);
|
|
||||||
// update the file, as needed
|
|
||||||
serveHelpers.updateFileIfNeeded(uri, result.dataValues.outpoint, result.dataValues.outpoint);
|
|
||||||
// 3. if a match was not found locally, use the daemon to retrieve the claim & return the db data once it is created
|
|
||||||
} else {
|
|
||||||
lbryApi
|
|
||||||
.resolveUri(uri)
|
|
||||||
.then(result => {
|
|
||||||
if (result.claim && isFreePublicClaim(result.claim)) { // check to see if the claim is free & public
|
|
||||||
// get claim and serve
|
|
||||||
serveHelpers
|
|
||||||
.getClaimAndReturnResponse(uri, result.claim.address, result.claim.height)
|
|
||||||
.then(result => {
|
|
||||||
resolve(result.dataValues);
|
|
||||||
})
|
|
||||||
.catch(error => reject(error));
|
|
||||||
} else {
|
|
||||||
logger.debug('Resolve did not return a free, public claim');
|
|
||||||
resolve(null);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => reject(error));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => reject(error));
|
|
||||||
});
|
|
||||||
return deferred;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,40 +59,6 @@ function checkLocalDbForClaims (name, shortUrl) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function getClaimAndUpdate (uri, address, height) {
|
|
||||||
// // 1. get the claim
|
|
||||||
// lbryApi
|
|
||||||
// .getClaim(uri)
|
|
||||||
// .then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => {
|
|
||||||
// logger.debug(' Get returned outpoint: ', outpoint);
|
|
||||||
// // 2. update the entry in db
|
|
||||||
// db.File
|
|
||||||
// .update({
|
|
||||||
// outpoint,
|
|
||||||
// height, // note: height is coming from the 'resolve', not 'get'.
|
|
||||||
// address, // note: address is coming from the 'resolve', not 'get'.
|
|
||||||
// fileName: file_name,
|
|
||||||
// filePath: download_path,
|
|
||||||
// fileType: mime_type,
|
|
||||||
// nsfw : metadata.stream.metadata.nsfw,
|
|
||||||
// }, {
|
|
||||||
// where: {
|
|
||||||
// name,
|
|
||||||
// claimId: claim_id,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then(result => {
|
|
||||||
// logger.debug('successfully updated mysql record', result);
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// logger.error('sequelize error', error);
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// logger.error(`error while getting claim for ${uri} >> `, error);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
serveFile ({ fileName, fileType, filePath }, res) {
|
serveFile ({ fileName, fileType, filePath }, res) {
|
||||||
logger.info(`serving file ${fileName}`);
|
logger.info(`serving file ${fileName}`);
|
||||||
|
@ -122,25 +88,27 @@ module.exports = {
|
||||||
res.status(200).render('show', { layout: 'show', fileInfo });
|
res.status(200).render('show', { layout: 'show', fileInfo });
|
||||||
},
|
},
|
||||||
showFileLite (fileInfo, res) {
|
showFileLite (fileInfo, res) {
|
||||||
|
logger.debug('showing file lite');
|
||||||
res.status(200).render('showLite', { layout: 'show', fileInfo });
|
res.status(200).render('showLite', { layout: 'show', fileInfo });
|
||||||
},
|
},
|
||||||
getClaimIdByShortUrl (name, shortUrl) {
|
getClaimIdByShortUrl (shortUrl, name) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
lbryApi.getClaimsList(name) // use the daemon to check for claims list
|
logger.debug('getting claims list from lbrynet');
|
||||||
.then(({ claims }) => { // if no claims were found, check locally for possible claims
|
// use the daemon to check for claims list
|
||||||
|
lbryApi.getClaimsList(name)
|
||||||
|
.then(({ claims }) => {
|
||||||
logger.debug('Number of claims from getClaimsList:', claims.length);
|
logger.debug('Number of claims from getClaimsList:', claims.length);
|
||||||
|
// if no claims were found, check locally for possible claims
|
||||||
if (claims.length === 0) {
|
if (claims.length === 0) {
|
||||||
logger.debug('no claims found with getClaimsList');
|
|
||||||
return checkLocalDbForClaims(name, shortUrl);
|
return checkLocalDbForClaims(name, shortUrl);
|
||||||
} else {
|
} else {
|
||||||
logger.debug('claims were found by getClaimsList');
|
|
||||||
return claims;
|
return claims;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(claims => { // handle the claims list
|
// handle the claims list
|
||||||
logger.debug('Claims ready for filtering:', claims);
|
.then(claims => {
|
||||||
|
logger.debug('Claims ready for filtering');
|
||||||
const regex = new RegExp(`^${shortUrl}`);
|
const regex = new RegExp(`^${shortUrl}`);
|
||||||
logger.debug('regex:', regex);
|
|
||||||
const filteredClaimsList = claims.filter(claim => {
|
const filteredClaimsList = claims.filter(claim => {
|
||||||
return regex.test(claim.claim_id);
|
return regex.test(claim.claim_id);
|
||||||
});
|
});
|
||||||
|
@ -164,10 +132,9 @@ module.exports = {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return deferred;
|
|
||||||
},
|
},
|
||||||
getShortUrlByClaimId (name, claimId) {
|
getShortUrlFromClaimId (name, claimId) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 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
|
||||||
|
@ -179,115 +146,5 @@ module.exports = {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return deferred;
|
|
||||||
},
|
|
||||||
determineShortUrl (claimId, claimList) {
|
|
||||||
return determineShortUrl(claimId, claimList);
|
|
||||||
},
|
|
||||||
updateFileIfNeeded (name, claimId, localOutpoint, localHeight) {
|
|
||||||
// const uri = `${name}#${claimId}`;
|
|
||||||
// logger.debug(`Initiating resolve to check outpoint for ${uri}`);
|
|
||||||
// // 1. resolve claim
|
|
||||||
// lbryApi
|
|
||||||
// .resolveUri(uri)
|
|
||||||
// .then(result => {
|
|
||||||
// // check to make sure the result is a claim
|
|
||||||
// if (!result.claim) {
|
|
||||||
// logger.debug('resolve did not return a claim');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// // logger.debug('resolved result:', result);
|
|
||||||
// const resolvedOutpoint = `${result.claim.txid}:${result.claim.nout}`;
|
|
||||||
// const resolvedHeight = result.claim.height;
|
|
||||||
// const resolvedAddress = result.claim.address;
|
|
||||||
// logger.debug('database outpoint:', localOutpoint);
|
|
||||||
// logger.debug('resolved outpoint:', resolvedOutpoint);
|
|
||||||
// // 2. if the outpoint's match, no further work needed
|
|
||||||
// if (localOutpoint === resolvedOutpoint) {
|
|
||||||
// logger.debug('local outpoint matched');
|
|
||||||
// // 2. if the outpoints don't match, check the height
|
|
||||||
// } else if (localHeight > resolvedHeight) {
|
|
||||||
// logger.debug('local height was greater than resolved height');
|
|
||||||
// // 2. get the resolved claim
|
|
||||||
// } else {
|
|
||||||
// logger.debug(`local outpoint did not match for ${uri}. Initiating update.`);
|
|
||||||
// getClaimAndUpdate(uri, resolvedAddress, resolvedHeight);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// logger.error(error);
|
|
||||||
// });
|
|
||||||
},
|
|
||||||
getClaimAndHandleResponse (uri, address, height, resolve, reject) {
|
|
||||||
lbryApi
|
|
||||||
.getClaim(uri)
|
|
||||||
.then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => {
|
|
||||||
// create entry in the db
|
|
||||||
logger.silly(`creating "${name}" record in File db`);
|
|
||||||
db.File
|
|
||||||
.create({
|
|
||||||
name,
|
|
||||||
claimId : claim_id,
|
|
||||||
address, // note: comes from parent 'resolve,' not this 'get' call
|
|
||||||
outpoint,
|
|
||||||
height, // note: comes from parent 'resolve,' not this 'get' call
|
|
||||||
fileName: file_name,
|
|
||||||
filePath: download_path,
|
|
||||||
fileType: mime_type,
|
|
||||||
nsfw : metadata.stream.metadata.nsfw,
|
|
||||||
})
|
|
||||||
.then(result => {
|
|
||||||
logger.debug('successfully created mysql record');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logger.error('sequelize create error', error);
|
|
||||||
});
|
|
||||||
// resolve the request
|
|
||||||
resolve({
|
|
||||||
name,
|
|
||||||
claimId : claim_id,
|
|
||||||
fileName: file_name,
|
|
||||||
filePath: download_path,
|
|
||||||
fileType: mime_type,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getClaimAndReturnResponse (uri, address, height) {
|
|
||||||
const deferred = new Promise((resolve, reject) => {
|
|
||||||
lbryApi
|
|
||||||
.getClaim(uri)
|
|
||||||
.then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => {
|
|
||||||
// create entry in the db
|
|
||||||
logger.silly(`Creating new File record`);
|
|
||||||
db.File
|
|
||||||
.create({
|
|
||||||
name,
|
|
||||||
claimId : claim_id,
|
|
||||||
address, // note: passed as an arguent, not from this 'get' call
|
|
||||||
outpoint,
|
|
||||||
height, // note: passed as an arguent, not from this 'get' call
|
|
||||||
fileName: file_name,
|
|
||||||
filePath: download_path,
|
|
||||||
fileType: mime_type,
|
|
||||||
nsfw : metadata.stream.metadata.nsfw,
|
|
||||||
})
|
|
||||||
.then(result => {
|
|
||||||
logger.debug('Successfully created File record');
|
|
||||||
resolve(result); // note: result.dataValues ?
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logger.debug('db.File.create error');
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logger.debug('lbryApi.getClaim error');
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return deferred;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const { serveFile, showFile, showFileLite } = require('../helpers/libraries/serveHelpers.js');
|
const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/libraries/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 SERVE = 'SERVE';
|
const SERVE = 'SERVE';
|
||||||
const SHOW = 'SHOW';
|
const SHOW = 'SHOW';
|
||||||
|
@ -69,38 +70,54 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
logger.debug('claim name = ', name);
|
logger.debug('claim name = ', name);
|
||||||
logger.debug('method =', method);
|
logger.debug('method =', method);
|
||||||
|
// 1. retrieve the asset and information
|
||||||
getAsset(claimType, channelName, shortUrl, fullClaimId, name)
|
getAsset(claimType, channelName, shortUrl, fullClaimId, name)
|
||||||
.then(fileInfo => {
|
// 2. serve or show
|
||||||
// add file extension to the file info
|
.then(fileInfo => {
|
||||||
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.'));
|
logger.debug('asset was retrieved');
|
||||||
// test logging
|
// add file extension to the file info
|
||||||
logger.debug(fileInfo);
|
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.'));
|
||||||
// serve or show
|
// test logging
|
||||||
if (!fileInfo) {
|
logger.debug(fileInfo);
|
||||||
res.status(200).render('noClaims');
|
// serve or show
|
||||||
return;
|
if (!fileInfo) {
|
||||||
}
|
res.status(200).render('noClaims');
|
||||||
switch (method) {
|
return;
|
||||||
case SERVE:
|
}
|
||||||
serveFile(fileInfo, res);
|
switch (method) {
|
||||||
break;
|
case SERVE:
|
||||||
case SHOWLITE:
|
serveFile(fileInfo, res);
|
||||||
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
break;
|
||||||
showFileLite(fileInfo, res);
|
case SHOWLITE:
|
||||||
break;
|
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
||||||
case SHOW:
|
showFileLite(fileInfo, res);
|
||||||
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
break;
|
||||||
|
case SHOW:
|
||||||
|
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
||||||
|
getShortUrlFromClaimId(fileInfo.claimId, fileInfo.name)
|
||||||
|
.then(shortUrl => {
|
||||||
|
fileInfo['shortUrl'] = shortUrl;
|
||||||
showFile(fileInfo, res);
|
showFile(fileInfo, res);
|
||||||
break;
|
})
|
||||||
default:
|
.catch(error => {
|
||||||
logger.error('I did not recognize that method');
|
console.log('thowing error...');
|
||||||
break;
|
throw error;
|
||||||
}
|
});
|
||||||
})
|
break;
|
||||||
.catch(error => {
|
default:
|
||||||
logger.error(error);
|
logger.error('I did not recognize that method');
|
||||||
});
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 3. update the database
|
||||||
|
.then(() => {
|
||||||
|
logger.debug('update db / create new record');
|
||||||
|
// if asset was found locally, update db (resolve the claim to see if a newer version exists and then get && update db if needed)
|
||||||
|
// if asset was retrieved from lbrynet, create db record
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
handleRequestError('serve', originalUrl, ip, error, res);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// route to serve the winning asset at a claim
|
// route to serve the winning asset at a claim
|
||||||
app.get('/:name', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
<h2 class="subheader">Links</h2>
|
<h2 class="subheader">Links</h2>
|
||||||
{{!--short direct link to asset--}}
|
{{!--short direct link to asset--}}
|
||||||
<div class="share-option">
|
<div class="share-option">
|
||||||
<a href="/{{fileInfo.name}}/{{fileInfo.shortUrl}}{{fileInfo.fileExt}}">Permanent Short Link</a>
|
<a href="/{{fileInfo.shortUrl}}/{{fileInfo.name}}{{fileInfo.fileExt}}">Permanent Short Link</a>
|
||||||
(most convenient)
|
(most convenient)
|
||||||
<div class="input-error" id="input-error-copy-short-link" hidden="true"></div>
|
<div class="input-error" id="input-error-copy-short-link" hidden="true"></div>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="text" id="short-link" class="link" readonly spellcheck="false" value="https://spee.ch/{{fileInfo.name}}/{{fileInfo.shortUrl}}{{fileInfo.fileExt}}" onclick="select()"/>
|
<input type="text" id="short-link" class="link" readonly spellcheck="false" value="https://spee.ch/{{fileInfo.shortUrl}}/{{fileInfo.name}}{{fileInfo.fileExt}}" onclick="select()"/>
|
||||||
<button class="copy-button" data-elementtocopy="short-link" onclick="copyToClipboard(event)">copy</button>
|
<button class="copy-button" data-elementtocopy="short-link" onclick="copyToClipboard(event)">copy</button>
|
||||||
</div>
|
</div>
|
||||||
{{!-- link to show route for asset--}}
|
{{!-- link to show route for asset--}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue