I'm using two routes - one for reading sample and one for reading full-book. And ofcourse for sample, I don't have to worry about if user purchased the book or not. While for full-book, I have to...
hence, I'm separating the epub2web in to two cachedir - one call it as "sample" in a sample nodejs route and another one call it - "bookreader" dir in its own route.
So, a user first clicks on sample and reads the book ok - a json and book gets created under sample directory just fine and reads just fine.
Now, when a user buys a book and then clicks on read book (fullbook) - server attaches a different cachedir called - "bookreader" however the actual book and json still gets created in the old "sample" folder even though I'm attaching "bookreader" cache directory.
app.get('/lookinside...) {
var cacheDir = "./public/sample";
var myTemplateName = 'template1';
var myTemplateHtml = fs.readFileSync('./public/testreader2.html');
var bookfile = linkToBook;
var epubDir = cacheDir;
// add custom reading template
epub2web.attach(cacheDir);
epub2web.addTemplate(myTemplateName, myTemplateHtml.toString());
epub2web.attach(cacheDir);
// attach to any cache dir you want for cache location of exploded epubs
epub2web.webify(
linkToBook, /* full path of epub file */
myTemplateName, /* template name for reading system */
function (err, cacheId, htmlApp) { /* callback after webify complete */
// the htmlApp is the whole reading system,
// fully configured for this cacheId, so
// just pass it right to the browser
var cacheurl = '/sample/' + cacheId + '/' + req.query.eid ;
res.writeHead(302, {
'Location': cacheurl
});
res.end();
});
}
app.get('/readfullbook...) {
var cacheDir = "./public/bookreader";;
var myTemplateName = 'template2';
var myTemplateHtml = fs.readFileSync('./public/testreader.html');
var bookfile = linkToBook;
var epubDir = cacheDir;
// add custom reading template
epub2web.attach(cacheDir);
epub2web.addTemplate(myTemplateName, myTemplateHtml.toString());
// attach to any cache dir you want for cache location of exploded epubs
epub2web.attach(cacheDir);
epub2web.webify(
linkToBook, /* full path of epub file */
myTemplateName, /* template name for reading system */
function (err, cacheId, htmlApp) { /* callback after webify complete */
// the htmlApp is the whole reading system,
// fully configured for this cacheId, so
// just pass it right to the browser
var cacheurl = '/bookreader/' + cacheId + '/' + req.query.eid;
logger.verbose("/readbook cacheurl:" + cacheurl);
res.writeHead(302, {
'Location': cacheurl
});
res.end();
});
}