copy paste support
This commit is contained in:
parent
adeda1b0f5
commit
3bd9d47a3c
4 changed files with 27 additions and 3 deletions
2
app.js
2
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({
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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('/');
|
||||
})
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ function extension(string) {
|
|||
<form action="/" method="post" encType="multipart/form-data">
|
||||
<!---->
|
||||
<div id="dropArea">
|
||||
<p class="dragregion">Upload a file or drag n' drop into the dashed region</p>
|
||||
<p class="dragregion">Upload a file, copy paste, or drag n' drop into the dashed region</p>
|
||||
<div id="gallery"></div>
|
||||
<p class="dragregion"><input class="" type="file" id="fileupload" name="fileupload"><input type="submit" value="Upload"></p>
|
||||
<p class="dragregion">Click the file to copy the url</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue