...
 
Commits (2)
......@@ -79,19 +79,7 @@ module.exports = function (options, plugins) {
}
try {
if (ifModifiedSince) {
checkModifiedTime(function(modified) {
if (modified) {
doGet();
} else {
res.sendStatus(304);
}
});
} else {
doGet();
}
function doGet() {
if (!ifModifiedSince || checkModifiedTime()) {
getRendition(function (renditionData, lastModifiedTime) {
if (renditionData) {
let contentType;
......@@ -118,6 +106,8 @@ module.exports = function (options, plugins) {
throw new Error("Missing rendition data");
}
});
} else {
res.sendStatus(304);
}
} catch (err) {
log.error("Problem generating image: ", err);
......@@ -166,21 +156,25 @@ module.exports = function (options, plugins) {
}
function checkModifiedTime(cb) {
/* Get last modified date of original */
sc.get(slingImg + "/jcr:content", 0, function(err, data) {
if (!err && data && data._jcr_lastModified) {
async function checkModifiedTime() {
try {
/* Get last modified date of original */
const data = await sc.get(slingImg + "/jcr:content", 0);
if (data && data._jcr_lastModified) {
originalMtime = Date.parse(data._jcr_lastModified);
}
if (!originalMtime || Date.parse(ifModifiedSince) < originalMtime) {
// Modified
cb(true);
return true;
} else {
// Not modified
cb(false);
return false;
}
});
} catch(error) {
return true;
}
};
/********************************************************************************************/
......@@ -262,40 +256,35 @@ module.exports = function (options, plugins) {
}
}
function checkRenditionMtime(renditionMtime, fromRenditionBacking) {
async function checkRenditionMtime(renditionMtime, fromRenditionBacking) {
/* Get last modified date of original */
if (originalMtime) {
checkTimes();
} else {
sc.get(slingImg + "/jcr:content", 0, function(err, data) {
if (!err && data && data._jcr_lastModified) {
if (!originalMtime) {
try {
const data = await sc.get(slingImg + "/jcr:content", 0);
if (data && data._jcr_lastModified) {
originalMtime = Date.parse(data._jcr_lastModified);
}
checkTimes();
});
} catch(error) { /* ignore */ }
}
function checkTimes() {
if (!originalMtime) {
// Cannot get the original image to compare
if (processor) {
// No point in continuing
throw new Error("Cannot find original image");
} else {
// Attempt to generate image anyways, probably via the failover
generateRendition();
}
} else if (!renditionMtime || renditionMtime < originalMtime) {
if (renditionsBacking && !fromRenditionBacking) {
// Another server could have generated a new rendition
checkRenditionBacking();
} else {
generateRendition();
}
if (!originalMtime) {
// Cannot get the original image to compare
if (processor) {
// No point in continuing
throw new Error("Cannot find original image");
} else {
// Attempt to generate image anyways, probably via the failover
generateRendition();
}
} else if (!renditionMtime || renditionMtime < originalMtime) {
if (renditionsBacking && !fromRenditionBacking) {
// Another server could have generated a new rendition
checkRenditionBacking();
} else {
cb(renditionData, renditionMtime);
generateRendition();
}
} else {
cb(renditionData, renditionMtime);
}
};
......