-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
42 lines (32 loc) · 1.27 KB
/
app.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
###
imagenie: an image hosting service
###
express = require 'express'
imagenie = require './imagenie'
app = express.createServer()
app.use(express.bodyParser())
error_codes =
undefined: 201
'conflict': 409
'unknown': 500
app.put '/:album', (req, res) ->
imagenie.saveAlbum req.params.album, req.query.hash, req.body, (result) ->
res.send(JSON.stringify(result) + "\n", error_codes[result.error])
app.post '/:album', (req, res) ->
imagenie.saveImage req.params.album, req, (status, result, location) ->
body = JSON.stringify(result) + "\n"
headers = {
'Content-Length': body.length,
'Content-Type': 'application/json'}
headers['Location'] = location if location
res.writeHead status, headers
res.end body
app.get '/:album', (req, res) -> imagenie.getAlbum req.params.album, res
app.get '/:album/:id', (req, res) ->
if req.header('Accept', '*/*').indexOf('application/json') >= 0
imagenie.info(req.method, req.params.album, req.params.id, res)
else
imagenie.retrieve(req.method, req.params.album, 'original', req.params.id, res)
app.get '/:album/:size/:id', (req, res) ->
imagenie.retrieve(req.method, req.params.album, req.params.size, req.params.id, res)
app.listen 8000