@@ -32,10 +32,11 @@ function welcome(request,response)
32
32
console . log ( request . get ( 'Host' ) ) ;
33
33
var reply = {
34
34
usage : "Add a path, available paths: http://" + hostname + "/years and http://" + hostname + "/runeras" ,
35
- years : "use: /years/ to get all year infor or: /years/<key> for a specific value" ,
35
+ years : "use: /years/ to get all year info or: /years/<key> for a specific value" ,
36
36
runeras : "use: /runeras/ to get all run era info or: /runeras/<key> for a specific value" ,
37
37
queries : "Pass a query with: ?<akey>=<avalue>" ,
38
- example : "http://" + hostname + "/runeras/run_era?year=2015"
38
+ example : "http://" + hostname + "/runeras/run_era?year=2015" ,
39
+ output : "For year info, output=plain returns single values without square brackets"
39
40
}
40
41
response . send ( reply ) ;
41
42
}
@@ -47,9 +48,17 @@ function searchYear(request,response)
47
48
var key = request . params . mykey ;
48
49
var filters = request . query ;
49
50
var filtered_years = years ;
51
+ var output_value ;
50
52
51
53
for ( var reqkey in filters ) {
52
- filtered_years = filtered_years . filter ( a_year => a_year [ reqkey ] == filters [ reqkey ] ) ;
54
+ if ( reqkey == 'output' )
55
+ {
56
+ output_value = filters [ reqkey ] ;
57
+ }
58
+ else
59
+ {
60
+ filtered_years = filtered_years . filter ( a_year => a_year [ reqkey ] == filters [ reqkey ] ) ;
61
+ }
53
62
}
54
63
55
64
var reply ;
@@ -66,8 +75,21 @@ function searchYear(request,response)
66
75
}
67
76
68
77
console . log ( reply ) ;
69
- if ( reply . length == 1 ) reply = String ( reply [ 0 ] ) ;
70
78
79
+ // There are reasons to do this (i.e. to get CMSSW_5_3_32 instead of [ "CMSSW_5_3_32" ])
80
+ // but this is probably not a good idea in general
81
+ // adding a query parameter for output format: output=plain returns reply without square brackets
82
+ if ( reply . length == 1 && output_value == 'plain' )
83
+ {
84
+ if ( typeof reply [ 0 ] == 'string' )
85
+ {
86
+ reply = String ( reply [ 0 ] ) ;
87
+ }
88
+ else
89
+ {
90
+ reply = reply [ 0 ] ;
91
+ }
92
+ }
71
93
response . send ( reply ) ;
72
94
}
73
95
0 commit comments