fixed claimId and show workflow for spee.ch/example

This commit is contained in:
bill bittner 2017-11-27 10:22:47 -08:00
parent 279a44d760
commit 78bc163586
4 changed files with 21 additions and 11 deletions

View file

@ -3,6 +3,7 @@ const logger = require('winston');
const DEFAULT_THUMBNAIL = 'https://spee.ch/assets/img/video_thumb_default.png';
const NO_CHANNEL = 'NO_CHANNEL';
const NO_FILE = 'NO_FILE';
function chooseThumbnail (claimInfo, defaultThumbnail) {
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
@ -100,7 +101,7 @@ module.exports = {
return db.File.findOne({where: {claimId, name}})
.then(file => {
if (!file) {
return null;
return NO_FILE;
}
return file.dataValues;
});

View file

@ -16,7 +16,11 @@ function createOpenGraphInfo ({ claimId, name, fileExt }) {
module.exports = {
serveOrShowAsset (method, fileInfo, claimInfo, shortId, res) {
// add file extension to the file info
if (fileInfo.fileName) {
claimInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
} else {
claimInfo['fileExt'] = null;
}
// serve or show
switch (method) {
case SERVE:

View file

@ -159,7 +159,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
};
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimId}#${claimId}`);
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
return new Promise((resolve, reject) => {
this
.findAll({
@ -260,12 +260,12 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
order: [['effectiveAmount', 'DESC'], ['height', 'ASC']], // note: maybe height and effective amount need to switch?
})
.then(result => {
logger.debug('length of result', result.length);
switch (result.length) {
case 0:
return resolve(NO_CLAIM);
default:
logger.debug('getTopFreeClaimIdByClaimName result:', result.dataValues);
return resolve(result[0].claimId);
return resolve(result[0].dataValues.claimId);
}
})
.catch(error => {

View file

@ -228,17 +228,22 @@ module.exports = (app) => {
getClaimId(null, null, name, null)
.then(result => {
logger.debug('getClaimId result:', result);
if (result === NO_CLAIM) {
if (result === NO_CLAIM || result === NO_CHANNEL) {
return result;
}
// check for local file info and resolve the claim
return Promise.all([getLocalFileRecord(result, name), getClaimRecord(result, name), db.Claim.getShortClaimIdFromLongClaimId(result, name)]);
})
.then(result => {
if (result === NO_CLAIM || result === NO_CHANNEL) {
res.status(200).render('noClaim');
return;
} else if (result === NO_CHANNEL) {
res.status(200).render('noChannel');
return;
}
// check for local file info and resolve the claim
return Promise.all([getLocalFileRecord(result, name), getClaimRecord(result, name), db.Claim.getShortClaimIdFromLongClaimId(result, name)]);
})
.then(([fileInfo, claimInfo, shortClaimId]) => {
let fileInfo, claimInfo, shortClaimId;
[fileInfo, claimInfo, shortClaimId] = result;
logger.debug(`fileInfo:`, fileInfo);
logger.debug('claimInfo:', claimInfo);
logger.debug('shortClaimId:', shortClaimId);