@@ -38,91 +38,98 @@ else if (env === 'production') {
38
38
39
39
app . get ( '/' , routes . index ) ;
40
40
41
- app . get ( '/findImages' , function ( req , res ) {
41
+ app . get ( '/findImages' , ( req , res ) => {
42
42
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 ) => {
48
50
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 ) ) {
55
60
matches . push ( match [ 1 ] ) ;
56
61
}
62
+
57
63
res . write ( JSON . stringify ( matches ) ) ;
58
64
res . end ( ) ;
59
65
} ) ;
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
+ } ) ;
63
70
} ) ;
64
71
65
- app . get ( '/user/:userid' , function ( req , res ) {
72
+ app . get ( '/user/:userid' , ( req , res ) => {
66
73
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' , {
69
76
title : user . _id ,
70
- username : user . _id ,
71
- boards : user . boards
77
+ username : user . _id ,
78
+ boards : user . boards
72
79
} ) ;
73
80
} ) ;
74
81
} ) ;
75
82
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' , {
78
85
username : req . params . userid
79
- } ) ;
86
+ } ) ;
80
87
} ) ;
81
88
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 ) ;
85
92
} ) ;
86
93
} ) ;
87
94
88
- app . get ( '/user/:userid/:boardid' , function ( req , res ) {
95
+ app . get ( '/user/:userid/:boardid' , ( req , res ) => {
89
96
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' , {
97
103
title : user . _id ,
98
- username : user . _id ,
104
+ username : user . _id ,
99
105
board : board ,
100
106
images : images
101
107
} ) ;
102
108
} ) ;
103
- } else {
109
+ }
110
+ else {
104
111
res . send ( 404 , 'not found' ) ;
105
112
}
106
113
} ) ;
107
114
} ) ;
108
115
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' , {
111
118
username : req . params . userid ,
112
119
boardid : req . params . boardid
113
- } ) ;
120
+ } ) ;
114
121
} ) ;
115
122
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 => {
118
125
res . redirect ( '/user/' + req . params . userid + "/" + req . params . boardid )
119
126
} ) ;
120
127
} ) ;
121
128
122
- app . get ( '/image/:imageid' , function ( req , res ) {
129
+ app . get ( '/image/:imageid' , ( req , res ) => {
123
130
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' , {
126
133
title : "image" ,
127
134
image : image
128
135
} ) ;
0 commit comments