diff --git a/app.js b/app.js index 6f65ac4..cbdf04c 100644 --- a/app.js +++ b/app.js @@ -31,7 +31,7 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public'))); app.use(session({ - secret: process.env.EBSECRET || 'keyboard cat', + secret: process.env.EBSECRET || 'pleasechangeme', resave: false, saveUninitialized: false, store: new SQLiteStore({ diff --git a/public/js/index.js b/public/js/index.js index 0cffcf0..ae79fdc 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -47,6 +47,7 @@ function unhighlight(e) { } dropArea.addEventListener('drop', handleDrop, false) +window.addEventListener('paste', handlePaste); function handleDrop(e) { let dt = e.dataTransfer @@ -54,6 +55,26 @@ function handleDrop(e) { handleFiles(files) } +function handlePaste(e) { + // Get the data of clipboard + const clipboardItems = e.clipboardData.items; + const items = [].slice.call(clipboardItems).filter(function (item) { + // Filter the image items only + return item.type.indexOf('image') !== -1; + }); + if (items.length === 0) { + return; + } + + const item = items[0]; + // Get the blob of image + const blob = item.getAsFile(); + console.log(blob) + + uploadFile(blob) + previewFile(blob); +} + function handleFiles(files) { files = [...files] files.forEach(uploadFile) diff --git a/routes/index.js b/routes/index.js index 470bef0..ac6aab6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -75,12 +75,15 @@ router.get('/', function (req, res, next) { router.post('/', upload.array('fileupload'), function(req, res, next) { if (!req.files || Object.keys(req.files).length === 0) { + console.log(req) return res.status(400).send('No files were uploaded.'); } for (file in req.files) { db.run('INSERT INTO media (path) VALUES (?)', [req.files[file].filename], function (err) { - if (err) return next(err); + if (err) { console.log(err) + return next(err); + } return res.redirect('/'); }) } diff --git a/views/index.ejs b/views/index.ejs index 90ec324..9756034 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -30,7 +30,7 @@ function extension(string) {