aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorPitu <[email protected]>2017-01-18 03:29:46 -0300
committerPitu <[email protected]>2017-01-18 03:29:46 -0300
commitcf98005c4f68956813c61bf6a9b6a0fe02807bad (patch)
tree929bce1f1077253d82aedf3805833c89d462fce9 /controllers
parentadded admin auth for uploading to an album (diff)
downloadhost.fuwn.me-cf98005c4f68956813c61bf6a9b6a0fe02807bad.tar.xz
host.fuwn.me-cf98005c4f68956813c61bf6a9b6a0fe02807bad.zip
Better tables and showing album on upload view
Diffstat (limited to 'controllers')
-rw-r--r--controllers/albumsController.js12
-rw-r--r--controllers/uploadController.js26
2 files changed, 27 insertions, 11 deletions
diff --git a/controllers/albumsController.js b/controllers/albumsController.js
index 1f2d695..72c8177 100644
--- a/controllers/albumsController.js
+++ b/controllers/albumsController.js
@@ -14,14 +14,18 @@ albumsController.list = function(req, res, next){
fields.push('timestamp')
db.table('albums').select(fields).then((albums) => {
+
+ let ids = []
+ for(let album of albums){
+ album.date = new Date(album.timestamp * 1000)
+ album.date = album.date.getFullYear() + '-' + album.date.getMonth() + '-' + album.date.getDate() + ' ' + (album.date.getHours() < 10 ? '0' : '') + album.date.getHours() + ':' + (album.date.getMinutes() < 10 ? '0' : '') + album.date.getMinutes() + ':' + (album.date.getSeconds() < 10 ? '0' : '') + album.date.getSeconds()
+
+ ids.push(album.id)
+ }
if(req.headers.extended === undefined)
return res.json({ success: true, albums })
- let ids = []
- for(let album of albums)
- ids.push(album.id)
-
db.table('files').whereIn('albumid', ids).select('albumid').then((files) => {
let albumsCount = {}
diff --git a/controllers/uploadController.js b/controllers/uploadController.js
index c6b6e87..92671e0 100644
--- a/controllers/uploadController.js
+++ b/controllers/uploadController.js
@@ -78,15 +78,27 @@ uploadsController.list = function(req, res){
return res.status(401).send('not-authorized')
db.table('files').then((files) => {
+ db.table('albums').then((albums) => {
- for(let file of files){
- 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()
- }
+ console.log(files)
+
+ for(let file of files){
+ file.file = config.basedomain + config.uploads.prefix + file.name
+ file.date = new Date(file.timestamp * 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()
+
+ file.album = ''
+
+ if(file.albumid !== undefined)
+ for(let album of albums)
+ if(file.albumid === album.id)
+ file.album = album.name
+
+ }
+
+ return res.json(files)
+ })
- return res.json(files)
})
}