-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.coffee
59 lines (44 loc) · 1.58 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
###
Ok, Here We go.
###
express = require "express"
request = require "request"
app = express.createServer()
app.set 'view engine', 'jade'
app.set 'views', __dirname + '/views'
app.use express.static( __dirname + '/statics' )
app.use express.bodyParser()
app.use express.cookieParser()
app.get '/api/list*', ( req, res )->
#url = 'http://faxianla.com/mark/board.jsn?boardId=9344&offset=0&_=1331822332245'
url = 'http://faxianla.com/mark/popular.jsn?offset=0&_=1332062171115'
request.get url, ( $err, $res, $body )->
data = JSON.parse( $body )
json = []
for i in data.data
info =
intro: i.title
src: i.image_url
key = new Buffer( JSON.stringify( info ), 'utf-8' ).toString 'base64'
img = new Buffer( i.image_url, 'utf-8' ).toString 'base64'
console.log img
json.push(
id: key.replace( /\//gi, '|#|' )
intro: i.title
src: img
)
res.send json
app.get '/api/img/:key', ( req, res )->
src = new Buffer( req.params.key, 'base64' ).toString 'utf-8'
console.log src
request.get( src ).pipe( res )
app.get '/api/view/:key', ( req, res )->
key = req.params.key.replace( /\|\#\|/gi, '/' )
key = new Buffer( key, 'base64' ).toString 'utf-8'
info = JSON.parse key
info.src = info.src.replace 'metal', 'wood'
info.src = new Buffer( info.src, 'utf-8' ).toString 'base64'
res.send info
app.get '/', ( req, res )->
res.render 'index', layout: false
app.listen '8888'