diff options
Diffstat (limited to 'lib/index.js')
| -rw-r--r-- | lib/index.js | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/index.js b/lib/index.js index 8c089f5..6bdb722 100644 --- a/lib/index.js +++ b/lib/index.js @@ -21,7 +21,6 @@ var upload = require("./upload") var site = module.exports = {} site.init = function(){ app = express() - app.use('/p', express.static(path.join(__dirname, '../public'))) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: false })) @@ -39,6 +38,11 @@ site.init = function(){ res.json(img) }) }) + app.get("/p/get/", function(req, res){ + db.getLatest().then(function(img){ + res.json(img) + }) + }) app.get("/p/get/latest", function(req, res){ db.getLatest().then(function(img){ res.json(img) @@ -55,30 +59,37 @@ site.init = function(){ }) }) app.post("/p/upload", multer_upload.single('image'), function(req, res){ - upload.put("image", req.file, { - unacceptable: function(err){ - res.json({ error: err }) - }, - success: function(url){ - db.createImage(url).then(function(image){ - res.json(image) - }) - } - }) + upload.put("image", req.file, { + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + db.createImage(url).then(function(image){ + res.json(image) + }) + } + }) }) /* shaderblaster / asciiblaster apis */ app.post("/cgi-bin/im/shader/upload", multer_upload.single('qqfile'), function(req, res){ + var now = Math.floor(Date.now() / 1000) + var filename = sanitize(req.body.filename) + '_' + now + '.' + upload.getExtension() + var path = '/im/ab/' upload.put("shader", req.file, { - + filename, path, unacceptable: function(err){ res.json({ error: err }) }, success: function(url){ db.createShaderImage({ - username: req.body.username, - tag: req.body.tag, - url, + // date, name, dir, newfile, tag, remote_addr + date: now, + name: sanitize(req.body.username), + dir: 'ab', + newfile: filename, + tag: sanitize(req.body.tag) || 'plop', + remote_addr: req.ip || '127.0.0.1', }).then(function(image){ res.json(image) }) @@ -86,4 +97,9 @@ site.init = function(){ }) }) + /* public urls last */ + app.use('/p/', express.static(path.join(__dirname, '../public'))) } + +function sanitize (s){ return (s || "").replace(new RegExp("[^-_a-zA-Z0-9]", 'g'), "") } + |
