Changed upload from single file to array

This commit is contained in:
kanadeko 2017-01-16 05:22:19 -03:00
parent 3777c01465
commit f42202259d
3 changed files with 30 additions and 23 deletions

View File

@ -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

View File

@ -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,26 +37,33 @@ 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({
success: true,
files: [
{
name: req.file.filename,
size: req.file.size,
url: config.basedomain + req.file.filename
}
]
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: 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()

View File

@ -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')