Skip to content

Commit 015406a

Browse files
committed
add plain output option
1 parent ffec849 commit 015406a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

index.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ function welcome(request,response)
3232
console.log(request.get('Host'));
3333
var reply={
3434
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",
3636
runeras: "use: /runeras/ to get all run era info or: /runeras/<key> for a specific value",
3737
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"
3940
}
4041
response.send(reply);
4142
}
@@ -47,9 +48,17 @@ function searchYear(request,response)
4748
var key=request.params.mykey;
4849
var filters=request.query;
4950
var filtered_years = years;
51+
var output_value;
5052

5153
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+
}
5362
}
5463

5564
var reply;
@@ -66,8 +75,21 @@ function searchYear(request,response)
6675
}
6776

6877
console.log(reply);
69-
if (reply.length == 1) reply = String(reply[0]);
7078

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+
}
7193
response.send(reply);
7294
}
7395

0 commit comments

Comments
 (0)