diff --git a/routes/index.js b/routes/index.js index 947c342..cbc477d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,6 +3,9 @@ var BOB_mod_router = BOB_mod_express.Router(); var BOB_mod_path = require('path'); var BOB_mod_mkdirp = require('mkdirp'); var BOB_mod_os = require('os'); +var BOB_mod_fs = require('fs'); + +// var BOB_mod_fsExtra = require('fs-extra') var BOB_tol_gphotos = null; var BOB_tol_booth = null; @@ -12,6 +15,11 @@ var BOB_var_boothInProgress = 0; var BOB_var_gamepad = require("gamepad"); var BOB_var_ipAddress = '127.0.0.1'; +var BOB_var_path = "/home/troll/workspace/bobinoscope"; + +BOB_mod_mkdirp.sync("public/printer/todo"); +BOB_mod_mkdirp.sync("public/printer/done"); + /* GET home page. */ BOB_mod_router.get('/bobinoscope', function(req, res, next) { res.render('index', {serverIpAddress: BOB_var_ipAddress}); @@ -47,9 +55,51 @@ BOB_mod_router.get('/dslr/takepicture/:boothId/:pictId', function(req, res, next /* GET view page. */ BOB_mod_router.get('/download/final/hd/:pictId', function(req, res, next) { - res.download('/home/cocoon/workspace/bobinoscope/public/img/final/'+req.params.pictId); + res.download(BOB_var_path+'/public/img/final/'+req.params.pictId); +}); + + +/* GET view page. */ +BOB_mod_router.get('/print/bobinogramme/:pictId', function(req, res, next) { + var srcPath = BOB_mod_path.join(BOB_var_path, '/public/img/final/'+req.params.pictId); + var dstPath = BOB_mod_path.join(BOB_var_path, '/public/printer/todo/'+req.params.pictId); + copyFile(srcPath, dstPath, function(pErr) { + res.json({error: pErr}) + }) }); +BOB_mod_router.get('/print/list/todo', function(req, res, next) { + var todoPath = BOB_mod_path.join(BOB_var_path, '/public/img/final/'+req.params.pictId); + BOB_mod_fs.readdir(todoPath, function(pErr, pList) { + res.json({error: pErr, todos: pList}) + }) +}) + + +function copyFile(source, target, cb) { + var cbCalled = false; + + var rd = BOB_mod_fs.createReadStream(source); + rd.on("error", function(err) { + done(err); + }); + var wr = BOB_mod_fs.createWriteStream(target); + wr.on("error", function(err) { + done(err); + }); + wr.on("close", function(ex) { + done(); + }); + rd.pipe(wr); + + function done(err) { + if (!cbCalled) { + cb(err); + cbCalled = true; + } + } +} + // Initialize the library BOB_var_gamepad.init() diff --git a/views/view.ejs b/views/view.ejs index 23480d4..44ba92d 100644 --- a/views/view.ejs +++ b/views/view.ejs @@ -10,13 +10,22 @@
Cliquez sur le bobinogramme qui vous intéresse
pour afficher le menu