fixed missing file extension

This commit is contained in:
bill bittner 2017-11-27 14:52:46 -08:00
parent 369399ca98
commit 0142c168ae
2 changed files with 59 additions and 42 deletions

View file

@ -5,13 +5,6 @@ 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() === '') {
return defaultThumbnail;
}
return claimInfo.thumbnail;
}
module.exports = {
getClaimId (channelName, channelId, name, claimId) {
if (channelName) {
@ -82,7 +75,7 @@ module.exports = {
element['directUrlLong'] = `/${channelName}:${longChannelId}/${element.name}.${fileExtenstion}`;
element['showUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}`;
element['directUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}.${fileExtenstion}`;
element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL);
element['thumbnail'] = module.exports.chooseThumbnail(element, DEFAULT_THUMBNAIL);
});
}
resolve({
@ -112,8 +105,32 @@ module.exports = {
if (!claim) {
throw new Error('no record found in Claim table');
}
claim.dataValues.thumbnail = chooseThumbnail(claim.dataValues.thumbnail, DEFAULT_THUMBNAIL);
claim.dataValues.thumbnail = module.exports.chooseThumbnail(claim.dataValues.thumbnail, DEFAULT_THUMBNAIL);
claim.dataValues.fileExt = module.exports.determineFileExtensionFromContentType(claim.dataValues.contentType);
return claim.dataValues;
});
},
determineFileExtensionFromContentType (contentType) {
switch (contentType) {
case 'image/jpeg':
return 'jpeg';
case 'image/jpg':
return 'jpg';
case 'image/png':
return 'png';
case 'image/gif':
return 'gif';
case 'video/mp4':
return 'mp4';
default:
logger.info('showing unknown file type as image/jpeg');
return 'jpeg';
}
},
chooseThumbnail (claimInfo, defaultThumbnail) {
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
return defaultThumbnail;
}
return claimInfo.thumbnail;
},
};

View file

@ -177,43 +177,43 @@ function determineName (uri) {
function showAssetToClient (claimId, name, res) {
// check for local file info, resolve the claim, and get the short
return Promise
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
.then(([claimInfo, shortClaimId]) => {
logger.debug('claimInfo:', claimInfo);
logger.debug('shortClaimId:', shortClaimId);
return serveHelpers.showFile(claimInfo, shortClaimId, res);
})
.catch(error => {
throw error;
});
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
.then(([claimInfo, shortClaimId]) => {
logger.debug('claimInfo:', claimInfo);
logger.debug('shortClaimId:', shortClaimId);
return serveHelpers.showFile(claimInfo, shortClaimId, res);
})
.catch(error => {
throw error;
});
}
function showPlainAssetToClient (claimId, name, res) {
return Promise
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
.then(([claimInfo, shortClaimId]) => {
logger.debug('claimInfo:', claimInfo);
logger.debug('shortClaimId:', shortClaimId);
return serveHelpers.showFileLite(claimInfo, shortClaimId, res);
})
.catch(error => {
throw error;
});
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
.then(([claimInfo, shortClaimId]) => {
logger.debug('claimInfo:', claimInfo);
logger.debug('shortClaimId:', shortClaimId);
return serveHelpers.showFileLite(claimInfo, shortClaimId, res);
})
.catch(error => {
throw error;
});
}
function serveAssetToClient (claimId, name, res) {
return getLocalFileRecord(claimId, name)
.then(fileInfo => {
logger.debug('fileInfo:', fileInfo);
if (fileInfo) {
return serveHelpers.serveFile(fileInfo, res);
} else {
return res.status(307).json({status: 'success', message: 'resource temporarily unavailable'});
}
})
.catch(error => {
throw error;
});
.then(fileInfo => {
logger.debug('fileInfo:', fileInfo);
if (fileInfo) {
return serveHelpers.serveFile(fileInfo, res);
} else {
return res.status(307).json({status: 'success', message: 'resource temporarily unavailable'});
}
})
.catch(error => {
throw error;
});
}
module.exports = (app) => {
@ -259,11 +259,11 @@ module.exports = (app) => {
}
// show, showlite, or serve
switch (responseType) {
case SERVE:
case SHOW:
return showAssetToClient(claimId, name, res);
case SHOWLITE:
return showPlainAssetToClient(claimId, name, res);
case SHOW:
case SERVE:
return serveAssetToClient(claimId, name, res);
default:
break;
@ -303,11 +303,11 @@ module.exports = (app) => {
}
// show, showlite, or serve
switch (responseType) {
case SERVE:
case SHOW:
return showAssetToClient(claimId, name, res);
case SHOWLITE:
return showPlainAssetToClient(claimId, name, res);
case SHOW:
case SERVE:
return serveAssetToClient(claimId, name, res);
default:
break;