summaryrefslogtreecommitdiff
path: root/lib/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/index.js')
-rw-r--r--lib/index.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/index.js b/lib/index.js
index 5100967..6d07dda 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -30,14 +30,21 @@ site.init = function(){
console.log('plop listening at http://5.k:%s', server.address().port)
})
- app.get("/p/:id", function(req, res){
- res.sendFile("index.html", {root: './public'})
- })
app.get("/p/get/random", function(req, res){
db.getRandom().then(function(img){
res.json(img)
})
})
+ app.get("/p/list/", function(req, res){
+ limit = parseInt(req.params.limit)
+ if (isNaN(limit)) limit = 20
+ else limit = Math.max(limit, 100)
+ offset = parseInt(req.params.offset)
+ if (isNaN(offset)) offset = 0
+ db.getIndex(limit, offset).then(function(img){
+ res.json(img)
+ })
+ })
app.get("/p/get/", function(req, res){
db.getLatest().then(function(img){
res.json(img)
@@ -102,6 +109,9 @@ site.init = function(){
})
/* public urls last */
+ app.get("/p/:id", function(req, res){
+ res.sendFile("index.html", {root: './public'})
+ })
app.use('/p/', express.static(path.join(__dirname, '../public')))
}