fixed missing file extension
This commit is contained in:
parent
369399ca98
commit
0142c168ae
2 changed files with 59 additions and 42 deletions
|
@ -5,13 +5,6 @@ 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';
|
const NO_FILE = 'NO_FILE';
|
||||||
|
|
||||||
function chooseThumbnail (claimInfo, defaultThumbnail) {
|
|
||||||
if (!claimInfo.thumbnail || claimInfo.thumbnail.trim() === '') {
|
|
||||||
return defaultThumbnail;
|
|
||||||
}
|
|
||||||
return claimInfo.thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getClaimId (channelName, channelId, name, claimId) {
|
getClaimId (channelName, channelId, name, claimId) {
|
||||||
if (channelName) {
|
if (channelName) {
|
||||||
|
@ -82,7 +75,7 @@ module.exports = {
|
||||||
element['directUrlLong'] = `/${channelName}:${longChannelId}/${element.name}.${fileExtenstion}`;
|
element['directUrlLong'] = `/${channelName}:${longChannelId}/${element.name}.${fileExtenstion}`;
|
||||||
element['showUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}`;
|
element['showUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}`;
|
||||||
element['directUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}.${fileExtenstion}`;
|
element['directUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}.${fileExtenstion}`;
|
||||||
element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL);
|
element['thumbnail'] = module.exports.chooseThumbnail(element, DEFAULT_THUMBNAIL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resolve({
|
resolve({
|
||||||
|
@ -112,8 +105,32 @@ module.exports = {
|
||||||
if (!claim) {
|
if (!claim) {
|
||||||
throw new Error('no record found in Claim table');
|
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;
|
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;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -177,43 +177,43 @@ function determineName (uri) {
|
||||||
function showAssetToClient (claimId, name, res) {
|
function showAssetToClient (claimId, name, res) {
|
||||||
// check for local file info, resolve the claim, and get the short
|
// check for local file info, resolve the claim, and get the short
|
||||||
return Promise
|
return Promise
|
||||||
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
|
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
|
||||||
.then(([claimInfo, shortClaimId]) => {
|
.then(([claimInfo, shortClaimId]) => {
|
||||||
logger.debug('claimInfo:', claimInfo);
|
logger.debug('claimInfo:', claimInfo);
|
||||||
logger.debug('shortClaimId:', shortClaimId);
|
logger.debug('shortClaimId:', shortClaimId);
|
||||||
return serveHelpers.showFile(claimInfo, shortClaimId, res);
|
return serveHelpers.showFile(claimInfo, shortClaimId, res);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPlainAssetToClient (claimId, name, res) {
|
function showPlainAssetToClient (claimId, name, res) {
|
||||||
return Promise
|
return Promise
|
||||||
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
|
.all([getClaimRecord(claimId, name), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)])
|
||||||
.then(([claimInfo, shortClaimId]) => {
|
.then(([claimInfo, shortClaimId]) => {
|
||||||
logger.debug('claimInfo:', claimInfo);
|
logger.debug('claimInfo:', claimInfo);
|
||||||
logger.debug('shortClaimId:', shortClaimId);
|
logger.debug('shortClaimId:', shortClaimId);
|
||||||
return serveHelpers.showFileLite(claimInfo, shortClaimId, res);
|
return serveHelpers.showFileLite(claimInfo, shortClaimId, res);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveAssetToClient (claimId, name, res) {
|
function serveAssetToClient (claimId, name, res) {
|
||||||
return getLocalFileRecord(claimId, name)
|
return getLocalFileRecord(claimId, name)
|
||||||
.then(fileInfo => {
|
.then(fileInfo => {
|
||||||
logger.debug('fileInfo:', fileInfo);
|
logger.debug('fileInfo:', fileInfo);
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
return serveHelpers.serveFile(fileInfo, res);
|
return serveHelpers.serveFile(fileInfo, res);
|
||||||
} else {
|
} else {
|
||||||
return res.status(307).json({status: 'success', message: 'resource temporarily unavailable'});
|
return res.status(307).json({status: 'success', message: 'resource temporarily unavailable'});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
|
@ -259,11 +259,11 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
// show, showlite, or serve
|
// show, showlite, or serve
|
||||||
switch (responseType) {
|
switch (responseType) {
|
||||||
case SERVE:
|
case SHOW:
|
||||||
return showAssetToClient(claimId, name, res);
|
return showAssetToClient(claimId, name, res);
|
||||||
case SHOWLITE:
|
case SHOWLITE:
|
||||||
return showPlainAssetToClient(claimId, name, res);
|
return showPlainAssetToClient(claimId, name, res);
|
||||||
case SHOW:
|
case SERVE:
|
||||||
return serveAssetToClient(claimId, name, res);
|
return serveAssetToClient(claimId, name, res);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -303,11 +303,11 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
// show, showlite, or serve
|
// show, showlite, or serve
|
||||||
switch (responseType) {
|
switch (responseType) {
|
||||||
case SERVE:
|
case SHOW:
|
||||||
return showAssetToClient(claimId, name, res);
|
return showAssetToClient(claimId, name, res);
|
||||||
case SHOWLITE:
|
case SHOWLITE:
|
||||||
return showPlainAssetToClient(claimId, name, res);
|
return showPlainAssetToClient(claimId, name, res);
|
||||||
case SHOW:
|
case SERVE:
|
||||||
return serveAssetToClient(claimId, name, res);
|
return serveAssetToClient(claimId, name, res);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue