Development #287
4 changed files with 21 additions and 11 deletions
|
@ -3,6 +3,7 @@ const logger = require('winston');
|
||||||
|
|
||||||
const DEFAULT_THUMBNAIL = 'https://spee.ch/assets/img/video_thumb_default.png';
|
const DEFAULT_THUMBNAIL = 'https://spee.ch/assets/img/video_thumb_default.png';
|
||||||
const NO_CHANNEL = 'NO_CHANNEL';
|
const NO_CHANNEL = 'NO_CHANNEL';
|
||||||
|
const NO_FILE = 'NO_FILE';
|
||||||
|
|
||||||
function chooseThumbnail (claimInfo, defaultThumbnail) {
|
function chooseThumbnail (claimInfo, defaultThumbnail) {
|
||||||
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
|
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
|
||||||
|
@ -100,7 +101,7 @@ module.exports = {
|
||||||
return db.File.findOne({where: {claimId, name}})
|
return db.File.findOne({where: {claimId, name}})
|
||||||
.then(file => {
|
.then(file => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return null;
|
return NO_FILE;
|
||||||
}
|
}
|
||||||
return file.dataValues;
|
return file.dataValues;
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,8 +16,12 @@ function createOpenGraphInfo ({ claimId, name, fileExt }) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
serveOrShowAsset (method, fileInfo, claimInfo, shortId, res) {
|
serveOrShowAsset (method, fileInfo, claimInfo, shortId, res) {
|
||||||
// add file extension to the file info
|
// add file extension to the file info
|
||||||
claimInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
|
if (fileInfo.fileName) {
|
||||||
// serve or show
|
claimInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
|
||||||
|
} else {
|
||||||
|
claimInfo['fileExt'] = null;
|
||||||
|
}
|
||||||
|
// serve or show
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case SERVE:
|
case SERVE:
|
||||||
module.exports.serveFile(fileInfo, claimInfo, shortId, res);
|
module.exports.serveFile(fileInfo, claimInfo, shortId, res);
|
||||||
|
|
|
@ -159,7 +159,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
|
Claim.getShortClaimIdFromLongClaimId = function (claimId, claimName) {
|
||||||
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimId}#${claimId}`);
|
logger.debug(`Claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this
|
this
|
||||||
.findAll({
|
.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?
|
order: [['effectiveAmount', 'DESC'], ['height', 'ASC']], // note: maybe height and effective amount need to switch?
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
logger.debug('length of result', result.length);
|
||||||
switch (result.length) {
|
switch (result.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return resolve(NO_CLAIM);
|
return resolve(NO_CLAIM);
|
||||||
default:
|
default:
|
||||||
logger.debug('getTopFreeClaimIdByClaimName result:', result.dataValues);
|
return resolve(result[0].dataValues.claimId);
|
||||||
return resolve(result[0].claimId);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -228,17 +228,22 @@ module.exports = (app) => {
|
||||||
getClaimId(null, null, name, null)
|
getClaimId(null, null, name, null)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
logger.debug('getClaimId result:', 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');
|
res.status(200).render('noClaim');
|
||||||
return;
|
return;
|
||||||
} else if (result === NO_CHANNEL) {
|
} else if (result === NO_CHANNEL) {
|
||||||
res.status(200).render('noChannel');
|
res.status(200).render('noChannel');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check for local file info and resolve the claim
|
let fileInfo, claimInfo, shortClaimId;
|
||||||
return Promise.all([getLocalFileRecord(result, name), getClaimRecord(result, name), db.Claim.getShortClaimIdFromLongClaimId(result, name)]);
|
[fileInfo, claimInfo, shortClaimId] = result;
|
||||||
})
|
|
||||||
.then(([fileInfo, claimInfo, shortClaimId]) => {
|
|
||||||
logger.debug(`fileInfo:`, fileInfo);
|
logger.debug(`fileInfo:`, fileInfo);
|
||||||
logger.debug('claimInfo:', claimInfo);
|
logger.debug('claimInfo:', claimInfo);
|
||||||
logger.debug('shortClaimId:', shortClaimId);
|
logger.debug('shortClaimId:', shortClaimId);
|
||||||
|
|
Loading…
Reference in a new issue