diff --git a/README.md b/README.md index af13977..4d60c9b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ ![loli-safe](https://a.safe.moe/jcutlz.png) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/kanadeko/Kuro/master/LICENSE) +[![Chat / Support](https://img.shields.io/badge/Chat%20%2F%20Support-discord-7289DA.svg?style=flat-square)](https://discord.gg/5g6vgwn) + # lolisafe, a small safe worth protecting. ## Sites using loli-safe diff --git a/controllers/albumsController.js b/controllers/albumsController.js index a8dcb96..7b9cc46 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -155,7 +155,7 @@ albumsController.get = function(req, res, next) { file.file = basedomain + '/' + file.name let ext = path.extname(file.name).toLowerCase() - if (utils.extensions.includes(ext)) { + if (utils.imageExtensions.includes(ext) || utils.videoExtensions.includes(ext)) { file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png' utils.generateThumbs(file) } diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 08f431f..850ab17 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -187,7 +187,7 @@ uploadsController.processFilesForDisplay = function(req, res, files, existingFil for (let file of files) { let ext = path.extname(file.name).toLowerCase() - if (utils.extensions.includes(ext)) { + if (utils.imageExtensions.includes(ext) || utils.videoExtensions.includes(ext)) { file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png' utils.generateThumbs(file) } @@ -232,17 +232,26 @@ uploadsController.delete = function(req, res) { } uploadsController.deleteFile = function(file) { - + const ext = path.extname(file).toLowerCase() return new Promise(function(resolve, reject) { fs.stat(path.join(__dirname, '..', config.uploads.folder, file), function(err, stats) { if (err) { return reject(err) } fs.unlink(path.join(__dirname, '..', config.uploads.folder, file), function(err) { if (err) { return reject(err) } - return resolve() + if(!utils.imageExtensions.includes(ext) && !utils.videoExtensions.includes(ext)) { + return resolve() + } + file = file.substr(0, file.lastIndexOf(".")) + ".png" + fs.stat(path.join(__dirname, '..', config.uploads.folder, "thumbs/", file), function(err, stats) { + if (err) { return reject(err) } + fs.unlink(path.join(__dirname, '..', config.uploads.folder, "thumbs/", file), function(err) { + if (err) { return reject(err) } + return resolve() + }) + }) }) }) }) - } uploadsController.list = function(req, res) { @@ -300,7 +309,7 @@ uploadsController.list = function(req, res) { userids.push(file.userid) let ext = path.extname(file.name).toLowerCase() - if (utils.extensions.includes(ext)) { + if (utils.imageExtensions.includes(ext) || utils.videoExtensions.includes(ext)) { file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png' utils.generateThumbs(file) } diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 5ddec82..ec056ab 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -5,7 +5,8 @@ const gm = require('gm') const ffmpeg = require('fluent-ffmpeg') const utilsController = {} -utilsController.extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webm', '.mp4'] +utilsController.imageExtensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png'] +utilsController.videoExtensions = ['.webm', '.mp4', '.wmv', '.avi', '.mov'] utilsController.getPrettyDate = function(date) { return date.getFullYear() + '-' @@ -26,7 +27,7 @@ utilsController.generateThumbs = function(file, basedomain) { let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs', file.name.slice(0, -ext.length) + '.png') fs.access(thumbname, (err) => { if (err && err.code === 'ENOENT') { - if (ext === '.webm' || ext === '.mp4') { + if (utilsController.videoExtensions.includes(ext)) { ffmpeg(path.join(__dirname, '..', config.uploads.folder, file.name)) .thumbnail({ timestamps: [0], diff --git a/pages/home.html b/pages/home.html index d9376cb..25648a0 100644 --- a/pages/home.html +++ b/pages/home.html @@ -82,7 +82,7 @@

diff --git a/public/js/home.js b/public/js/home.js index 2ec27e7..4412ac5 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -5,6 +5,7 @@ upload.token = localStorage.token; upload.maxFileSize; // add the album var to the upload so we can store the album id in there upload.album; +upload.myDropzone; upload.checkIfPublic = function(){ axios.get('/api/check') @@ -131,8 +132,8 @@ upload.prepareDropzone = function(){ 'token': upload.token }, init: function() { + upload.myDropzone = this; this.on('addedfile', function(file) { - myDropzone = this; document.getElementById('uploads').style.display = 'block'; }); // add the selected albumid, if an album is selected, as a header @@ -184,7 +185,7 @@ window.addEventListener('paste', function(event) { var file = new File([blob], "pasted-image."+blob.type.match(/(?:[^\/]*\/)([^;]*)/)[1]); file.type = blob.type; console.log(file); - myDropzone.addFile(file); + upload.myDropzone.addFile(file); } } }); diff --git a/routes/album.js b/routes/album.js index 2c084b4..20ccc26 100644 --- a/routes/album.js +++ b/routes/album.js @@ -28,7 +28,7 @@ routes.get('/a/:identifier', (req, res, next) => { file.file = basedomain + '/' + file.name let ext = path.extname(file.name).toLowerCase() - if (utils.extensions.includes(ext)) { + if (utils.imageExtensions.includes(ext) || utils.videoExtensions.includes(ext)) { file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png' /*