@@ -90,6 +90,16 @@ const getsurvey = async (query: string | ParsedQs, req: Request<{}>, res: Respon
90
90
res . redirect ( "/" ) ;
91
91
}
92
92
}
93
+
94
+
95
+ const add_query = ( query : Object , parsed : Object ) => {
96
+ Object . entries ( query ) . forEach ( ( [ key , value ] ) => {
97
+ if ( parsed [ key ] === undefined ) { // never overwrites parsed params
98
+ parsed [ key ] = value ;
99
+ }
100
+ } ) ;
101
+ }
102
+
93
103
// Test URL: https://raw.githubusercontent.com/Watts-Lab/surveyor/main/surveys/CRT.csv
94
104
// e.g. http://localhost:4000/s/?url=https://raw.githubusercontent.com/Watts-Lab/surveyor/main/surveys/CRT.csv&name=Mark
95
105
router . get ( "/s/" , csrfProtection , async ( req , res ) => {
@@ -121,8 +131,12 @@ router.get("/sa/:alias/", csrfProtection, async (req, res: Response) => {
121
131
return res . status ( 400 ) . send ( 'Invalid URL. Please Email Researcher for url' )
122
132
}
123
133
124
- const parsed = record [ 0 ]
134
+ let parsed = record [ 0 ]
125
135
136
+ // queryies in the url
137
+ if ( req . query ) {
138
+ add_query ( req . query , parsed ) ;
139
+ }
126
140
if ( parsed . status == 'inactive' ) {
127
141
return res . status ( 400 ) . send ( "URL has expired." )
128
142
}
@@ -163,15 +177,9 @@ router.get("/se/:encrypted", csrfProtection, async (req, res) => {
163
177
const decrypted = decrypt ( encrypted )
164
178
const parsed = await JSON . parse ( decrypted )
165
179
166
- // queryies in the url
167
- const queries : Object = req . query
168
-
169
- Object . entries ( queries ) . forEach ( ( [ key , value ] ) => { // encrypted takes precedence
170
- if ( parsed [ key ] === undefined ) {
171
- parsed [ key ] = value
172
- }
173
- } )
174
-
180
+ if ( req . query ) {
181
+ add_query ( req . query , parsed )
182
+ }
175
183
if ( ! ( parsed . url ) ) { // only query require is url
176
184
return res . status ( 400 ) . send ( "Wrong encryption. No URL is found." )
177
185
}
0 commit comments