...
 
Commits (2)
......@@ -79,7 +79,19 @@ module.exports = function (options, plugins) {
}
try {
if (!ifModifiedSince || checkModifiedTime()) {
if (ifModifiedSince) {
checkModifiedTime(function(modified) {
if (modified) {
doGet();
} else {
res.sendStatus(304);
}
});
} else {
doGet();
}
function doGet() {
getRendition(function (renditionData, lastModifiedTime) {
if (renditionData) {
let contentType;
......@@ -106,8 +118,6 @@ module.exports = function (options, plugins) {
throw new Error("Missing rendition data");
}
});
} else {
res.sendStatus(304);
}
} catch (err) {
log.error("Problem generating image: ", err);
......@@ -156,25 +166,21 @@ module.exports = function (options, plugins) {
}
async function checkModifiedTime() {
try {
/* Get last modified date of original */
const data = await sc.get(slingImg + "/jcr:content", 0);
if (data && data._jcr_lastModified) {
function checkModifiedTime(cb) {
/* Get last modified date of original */
sc.get(slingImg + "/jcr:content", 0, function(err, data) {
if (!err && data && data._jcr_lastModified) {
originalMtime = Date.parse(data._jcr_lastModified);
}
if (!originalMtime || Date.parse(ifModifiedSince) < originalMtime) {
// Modified
return true;
cb(true);
} else {
// Not modified
return false;
cb(false);
}
} catch(error) {
return true;
}
});
};
/********************************************************************************************/
......@@ -256,35 +262,40 @@ module.exports = function (options, plugins) {
}
}
async function checkRenditionMtime(renditionMtime, fromRenditionBacking) {
function checkRenditionMtime(renditionMtime, fromRenditionBacking) {
/* Get last modified date of original */
if (!originalMtime) {
try {
const data = await sc.get(slingImg + "/jcr:content", 0);
if (data && data._jcr_lastModified) {
if (originalMtime) {
checkTimes();
} else {
sc.get(slingImg + "/jcr:content", 0, function(err, data) {
if (!err && data && data._jcr_lastModified) {
originalMtime = Date.parse(data._jcr_lastModified);
}
} catch(error) { /* ignore */ }
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();
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();
}
} else {
generateRendition();
cb(renditionData, renditionMtime);
}
} else {
cb(renditionData, renditionMtime);
}
};
......