diff options
| -rw-r--r-- | lib/db/index.js | 12 | ||||
| -rw-r--r-- | lib/index.js | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/db/index.js b/lib/db/index.js index 6e36602..a9e29be 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -46,3 +46,15 @@ db.createImage = function(url){ db.createShaderImage = function(data){ return new ShaderImage(data).save() } +// select name,dir,newfile,count(*) as count from im_cmd where tag='ascii' group by name order by count desc; +db.getUserCounts = function(){ + return knex.column('name').column('dir').column('newfile').count('* as count').from('im_cmd').where('tag','ascii').groupBy('name').orderBy(knex.raw('count'), 'desc') +} +db.getLatestByUser = function(){ + return knex.max('id as id').count('* as count').column('name').from('im_cmd').where('tag','ascii').groupBy('name').orderBy('count', 'desc') + // raw('SELECT MAX(id) as id, COUNT(*) as count, name FROM im_cmd WHERE tag='ascii' GROUP BY name') +} +db.getPhotoblasterImages = function(ids) { + return ShaderImage.query(qb => { return qb.where('id', 'in', ids) }).fetchAll() +} + diff --git a/lib/index.js b/lib/index.js index 7385d2f..d894b8e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -50,6 +50,17 @@ site.init = function(){ res.json(img) }) }) + app.get("/p/users/", function(req, res){ + db.getLatestByUser().then((latest) => { + var ids = latest.map(row => row.id) + db.getPhotoblasterImages(ids).then(rows => { + var lookup = {} + rows.forEach(row => lookup[row.id] = row) + latest.forEach(row => row.latest = lookup[row.id]) + res.json(latest) + }) + }) + }) app.get("/p/get/", function(req, res){ db.getLatest().then(function(img){ res.json(img) |
