aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.sample.js2
-rw-r--r--controllers/uploadController.js45
-rw-r--r--database/db.js2
3 files changed, 28 insertions, 21 deletions
diff --git a/config.sample.js b/config.sample.js
index e192385..c63d5fd 100644
--- a/config.sample.js
+++ b/config.sample.js
@@ -27,7 +27,7 @@ module.exports = {
maxsize: '512MB',
// The length of the random generated name for the uploaded files
- fileLength: 4,
+ fileLength: 32,
},
// Folder where to store logs
diff --git a/controllers/uploadController.js b/controllers/uploadController.js
index 83ca4ca..47d0d43 100644
--- a/controllers/uploadController.js
+++ b/controllers/uploadController.js
@@ -18,7 +18,7 @@ const storage = multer.diskStorage({
const upload = multer({
storage: storage,
limits: { fileSize: config.uploads.maxsize }
-}).single('files[]')
+}).array('files[]')
uploadsController.upload = function(req, res, next){
@@ -37,25 +37,32 @@ uploadsController.upload = function(req, res, next){
})
}
- db.table('files').insert({
- file: req.file.filename,
- original: req.file.originalname,
- type: req.file.mimetype,
- size: req.file.size,
- ip: req.ip,
- galleryid: gallery,
- created_at: Math.floor(Date.now() / 1000)
- }).then(() => {
- return res.json({
+ let files = []
+ req.files.forEach(function(file) {
+ files.push({
+ name: file.filename,
+ original: file.originalname,
+ type: file.mimetype,
+ size: file.size,
+ ip: req.ip,
+ galleryid: gallery,
+ created_at: Math.floor(Date.now() / 1000)
+ })
+ })
+
+ db.table('files').insert(files).then(() => {
+
+ res.json({
success: true,
- files: [
- {
- name: req.file.filename,
- size: req.file.size,
- url: config.basedomain + req.file.filename
+ files: files.map(file => {
+ return {
+ name: file.name,
+ size: file.size,
+ url: config.basedomain + file.name
}
- ]
+ })
})
+
})
})
@@ -70,8 +77,8 @@ uploadsController.list = function(req, res){
db.table('files').then((files) => {
for(let file of files){
- file.file = config.basedomain + config.uploads.prefix + file.file
- file.ext = file.file.split('.').pop()
+ file.file = config.basedomain + config.uploads.prefix + file.name
+ file.ext = file.name.split('.').pop()
file.date = new Date(file.created_at * 1000)
file.date = file.date.getFullYear() + '-' + file.date.getMonth() + '-' + file.date.getDate() + ' ' + (file.date.getHours() < 10 ? '0' : '') + file.date.getHours() + ':' + (file.date.getMinutes() < 10 ? '0' : '') + file.date.getMinutes() + ':' + (file.date.getSeconds() < 10 ? '0' : '') + file.date.getSeconds()
diff --git a/database/db.js b/database/db.js
index 2dc2005..d641c2e 100644
--- a/database/db.js
+++ b/database/db.js
@@ -10,7 +10,7 @@ let init = function(db, config){
db.schema.createTableIfNotExists('files', function (table) {
table.increments()
- table.string('file')
+ table.string('name')
table.string('original')
table.string('type')
table.string('size')