|
@@ -231,6 +231,7 @@ uploadsController.list = function(req, res){
|
|
.orderBy('id', 'DESC')
|
|
.orderBy('id', 'DESC')
|
|
.limit(25)
|
|
.limit(25)
|
|
.offset(25 * offset)
|
|
.offset(25 * offset)
|
|
|
|
+ .select('id', 'albumid', 'timestamp', 'name', 'userid')
|
|
.then((files) => {
|
|
.then((files) => {
|
|
db.table('albums').then((albums) => {
|
|
db.table('albums').then((albums) => {
|
|
|
|
|
|
@@ -240,6 +241,8 @@ uploadsController.list = function(req, res){
|
|
if(domain.hasOwnProperty('resolve'))
|
|
if(domain.hasOwnProperty('resolve'))
|
|
basedomain = domain.resolve
|
|
basedomain = domain.resolve
|
|
|
|
|
|
|
|
+ let userids = []
|
|
|
|
+
|
|
for(let file of files){
|
|
for(let file of files){
|
|
file.file = basedomain + '/' + file.name
|
|
file.file = basedomain + '/' + file.name
|
|
file.date = new Date(file.timestamp * 1000)
|
|
file.date = new Date(file.timestamp * 1000)
|
|
@@ -252,62 +255,79 @@ uploadsController.list = function(req, res){
|
|
if(file.albumid === album.id)
|
|
if(file.albumid === album.id)
|
|
file.album = album.name
|
|
file.album = album.name
|
|
|
|
|
|
- if(config.uploads.generateThumbnails === true){
|
|
+
|
|
-
|
|
+ if(user[0].username === 'root')
|
|
- let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webm', '.mp4']
|
|
+ if(file.userid !== undefined && file.userid !== null && file.userid !== '')
|
|
- for(let ext of extensions){
|
|
+ userids.push(file.userid)
|
|
- if(path.extname(file.name) === ext){
|
|
+
|
|
-
|
|
+ uploadsController.generateThumbs(file, basedomain)
|
|
- file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png'
|
|
|
|
-
|
|
|
|
- let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs') + '/' + file.name.slice(0, -ext.length) + '.png'
|
|
|
|
- fs.access(thumbname, function(err) {
|
|
|
|
- if (err && err.code === 'ENOENT') {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if (ext === '.webm' || ext === '.mp4') {
|
|
|
|
- ffmpeg('./' + config.uploads.folder + '/' + file.name)
|
|
|
|
- .thumbnail({
|
|
|
|
- timestamps: [0],
|
|
|
|
- filename: '%b.png',
|
|
|
|
- folder: './' + config.uploads.folder + '/thumbs',
|
|
|
|
- size: '200x?'
|
|
|
|
- })
|
|
|
|
- .on('error', function(error) {
|
|
|
|
- console.log('Error - ', error.message)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- let size = {
|
|
|
|
- width: 200,
|
|
|
|
- height: 200
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- gm('./' + config.uploads.folder + '/' + file.name)
|
|
|
|
- .resize(size.width, size.height + '>')
|
|
|
|
- .gravity('Center')
|
|
|
|
- .extent(size.width, size.height)
|
|
|
|
- .background('transparent')
|
|
|
|
- .write(thumbname, function (error) {
|
|
|
|
- if (error) console.log('Error - ', error)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return res.json({
|
|
+
|
|
- success: true,
|
|
+ if(user[0].username !== 'root') return res.json({ success: true, files })
|
|
- files
|
|
+
|
|
- })
|
|
+
|
|
|
|
+ if(userids.length === 0) return res.json({ success: true, files })
|
|
|
|
+
|
|
|
|
+ db.table('users').whereIn('id', userids).then((users) => {
|
|
|
|
+ for(let user of users)
|
|
|
|
+ for(let file of files)
|
|
|
|
+ if(file.userid === user.id)
|
|
|
|
+ file.username = user.username
|
|
|
|
|
|
|
|
+ return res.json({ success: true, files })
|
|
|
|
+ }).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
|
|
|
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+uploadsController.generateThumbs = function(file, basedomain){
|
|
|
|
+ if(config.uploads.generateThumbnails !== true) return
|
|
|
|
+
|
|
|
|
+ let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webm', '.mp4']
|
|
|
|
+ for(let ext of extensions){
|
|
|
|
+ if(path.extname(file.name).toLowerCase() === ext){
|
|
|
|
+
|
|
|
|
+ file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png'
|
|
|
|
+
|
|
|
|
+ let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs') + '/' + file.name.slice(0, -ext.length) + '.png'
|
|
|
|
+ fs.access(thumbname, function(err) {
|
|
|
|
+ if (err && err.code === 'ENOENT') {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (ext === '.webm' || ext === '.mp4') {
|
|
|
|
+ ffmpeg('./' + config.uploads.folder + '/' + file.name)
|
|
|
|
+ .thumbnail({
|
|
|
|
+ timestamps: [0],
|
|
|
|
+ filename: '%b.png',
|
|
|
|
+ folder: './' + config.uploads.folder + '/thumbs',
|
|
|
|
+ size: '200x?'
|
|
|
|
+ })
|
|
|
|
+ .on('error', function(error) {
|
|
|
|
+ console.log('Error - ', error.message)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ let size = {
|
|
|
|
+ width: 200,
|
|
|
|
+ height: 200
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ gm('./' + config.uploads.folder + '/' + file.name)
|
|
|
|
+ .resize(size.width, size.height + '>')
|
|
|
|
+ .gravity('Center')
|
|
|
|
+ .extent(size.width, size.height)
|
|
|
|
+ .background('transparent')
|
|
|
|
+ .write(thumbname, function (error) {
|
|
|
|
+ if (error) console.log('Error - ', error)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
module.exports = uploadsController
|
|
module.exports = uploadsController
|