@@ -38,91 +38,98 @@ else if (env === 'production') {
3838
3939app . get ( '/' , routes . index ) ;
4040
41- app . get ( '/findImages' , function ( req , res ) {
41+ app . get ( '/findImages' , ( req , res ) => {
4242 console . log ( 'getting images from' + req . query [ 'url' ] ) ;
43-
44- var req2 = http . get ( url . parse ( req . query [ 'url' ] ) , function ( urlres ) {
45- console . log ( "Got response: " + urlres . statusCode ) ;
46- var text = "" ;
47- urlres . on ( 'data' , function ( chunk : string ) {
43+
44+ let req2 = http . get ( url . parse ( req . query [ 'url' ] ) , urlMessage => {
45+ console . log ( "Got response: " + urlMessage . statusCode ) ;
46+
47+ let text = "" ;
48+
49+ urlMessage . on ( 'data' , ( chunk : string ) => {
4850 text += chunk ;
49- } ) ;
50- urlres . on ( 'end' , function ( ) {
51- console . log ( text ) ;
52- var re = / < i m g [ ^ > ] + s r c = [ \" \' ] ( [ ^ \' \" ] + ) [ \" \' ] / g;
53- var match , matches = [ ] ;
54- while ( match = re . exec ( text ) ) {
51+ } ) ;
52+
53+ urlMessage . on ( 'end' , ( ) => {
54+ console . log ( text ) ;
55+ const imageTagRegEx = / < i m g [ ^ > ] + s r c = [ \" \' ] ( [ ^ \' \" ] + ) [ \" \' ] / g;
56+
57+ let match : RegExpMatchArray ;
58+ let matches : string [ ] = [ ] ;
59+ while ( match = imageTagRegEx . exec ( text ) ) {
5560 matches . push ( match [ 1 ] ) ;
5661 }
62+
5763 res . write ( JSON . stringify ( matches ) ) ;
5864 res . end ( ) ;
5965 } ) ;
60- } ) . on ( 'error' , function ( a , e ) {
61- console . log ( "Got error: " + e . message ) ;
62- } ) ;
66+
67+ } ) . on ( 'error' , function ( a , e ) {
68+ console . log ( "Got error: " + e . message ) ;
69+ } ) ;
6370} ) ;
6471
65- app . get ( '/user/:userid' , function ( req , res ) {
72+ app . get ( '/user/:userid' , ( req , res ) => {
6673 console . log ( 'getting user ' + req . params . userid ) ;
67- db . getUser ( req . params . userid , function ( user ) {
68- res . render ( 'user' , {
74+ db . getUser ( req . params . userid , user => {
75+ res . render ( 'user' , {
6976 title : user . _id ,
70- username : user . _id ,
71- boards : user . boards
77+ username : user . _id ,
78+ boards : user . boards
7279 } ) ;
7380 } ) ;
7481} ) ;
7582
76- app . get ( '/user/:userid/newboard' , function ( req , res ) {
77- res . render ( 'newboard' , {
83+ app . get ( '/user/:userid/newboard' , ( req , res ) => {
84+ res . render ( 'newboard' , {
7885 username : req . params . userid
79- } ) ;
86+ } ) ;
8087} ) ;
8188
82- app . post ( '/user/:userid/newboard' , function ( req , res ) {
83- db . addBoard ( req . params . userid , req . param ( 'title' ) , req . param ( 'description' ) , function ( user ) {
84- res . redirect ( '/user/' + req . params . userid )
89+ app . post ( '/user/:userid/newboard' , ( req , res ) => {
90+ db . addBoard ( req . params . userid , req . param ( 'title' ) , req . param ( 'description' ) , user => {
91+ res . redirect ( '/user/' + req . params . userid ) ;
8592 } ) ;
8693} ) ;
8794
88- app . get ( '/user/:userid/:boardid' , function ( req , res ) {
95+ app . get ( '/user/:userid/:boardid' , ( req , res ) => {
8996 console . log ( 'getting ' + req . params . userid + ", " + req . params . boardid ) ;
90- db . getUser ( req . params . userid , function ( user ) {
91- var board = user . boards . filter ( function ( board ) {
92- return decodeURIComponent ( req . params . boardid ) === board . title ;
93- } ) [ 0 ] ;
94- if ( board ) {
95- db . getImages ( board . images , function ( images ) {
96- res . render ( 'board' , {
97+ db . getUser ( req . params . userid , user => {
98+ let board = user . boards . filter ( board => decodeURIComponent ( req . params . boardid ) === board . title ) [ 0 ] ;
99+
100+ if ( board ) {
101+ db . getImages ( board . images , images => {
102+ res . render ( 'board' , {
97103 title : user . _id ,
98- username : user . _id ,
104+ username : user . _id ,
99105 board : board ,
100106 images : images
101107 } ) ;
102108 } ) ;
103- } else {
109+ }
110+ else {
104111 res . send ( 404 , 'not found' ) ;
105112 }
106113 } ) ;
107114} ) ;
108115
109- app . get ( '/user/:userid/:boardid/newpin' , function ( req , res ) {
110- res . render ( 'newpin' , {
116+ app . get ( '/user/:userid/:boardid/newpin' , ( req , res ) => {
117+ res . render ( 'newpin' , {
111118 username : req . params . userid ,
112119 boardid : req . params . boardid
113- } ) ;
120+ } ) ;
114121} ) ;
115122
116- app . post ( '/user/:userid/:boardid/newpin' , function ( req , res ) {
117- db . addPin ( req . params . userid , req . params . boardid , req . param ( 'imageUri' ) , req . param ( 'link' ) , req . param ( 'caption' ) , function ( user ) {
123+ app . post ( '/user/:userid/:boardid/newpin' , ( req , res ) => {
124+ db . addPin ( req . params . userid , req . params . boardid , req . param ( 'imageUri' ) , req . param ( 'link' ) , req . param ( 'caption' ) , user => {
118125 res . redirect ( '/user/' + req . params . userid + "/" + req . params . boardid )
119126 } ) ;
120127} ) ;
121128
122- app . get ( '/image/:imageid' , function ( req , res ) {
129+ app . get ( '/image/:imageid' , ( req , res ) => {
123130 console . log ( 'getting image ' + req . params . imageid ) ;
124- db . getImage ( req . params . imageid , function ( image ) {
125- res . render ( 'image' , {
131+ db . getImage ( req . params . imageid , image => {
132+ res . render ( 'image' , {
126133 title : "image" ,
127134 image : image
128135 } ) ;
0 commit comments