Skip to content

Commit

Permalink
[api] os version mapping to prevent clashing
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Jul 21, 2015
1 parent 9824042 commit 341539a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ if (cluster.isMaster) {
apps:require('./parts/mgmt/apps.js')
}
};

var os_mapping = {
"unknown":"unk",
"qnx":"qnx",
"os/2":"os2",
"windows":"mw",
"open bsd":"ob",
"searchbot":"sb",
"sun os":"so",
"beos":"bo",
"mac osx":"o"
};

plugins.dispatch("/worker", {common:common});
// Checks app_key from the http request against "apps" collection.
Expand Down Expand Up @@ -403,7 +415,10 @@ if (cluster.isMaster) {
}

if (tmpParams.qstring.metrics["_os"] && tmpParams.qstring.metrics["_os_version"]) {
tmpParams.qstring.metrics["_os_version"] = tmpParams.qstring.metrics["_os"][0].toLowerCase() + tmpParams.qstring.metrics["_os_version"];
if(os_mapping[tmpParams.qstring.metrics["_os"].toLowerCase()])
tmpParams.qstring.metrics["_os_version"] = os_mapping[tmpParams.qstring.metrics["_os"].toLowerCase()] + tmpParams.qstring.metrics["_os_version"];
else
tmpParams.qstring.metrics["_os_version"] = tmpParams.qstring.metrics["_os"][0].toLowerCase() + tmpParams.qstring.metrics["_os_version"];
}
}
validateAppForWriteAPI(tmpParams);
Expand Down Expand Up @@ -507,7 +522,10 @@ if (cluster.isMaster) {
}

if (params.qstring.metrics["_os"] && params.qstring.metrics["_os_version"]) {
params.qstring.metrics["_os_version"] = params.qstring.metrics["_os"][0].toLowerCase() + params.qstring.metrics["_os_version"];
if(os_mapping[params.qstring.metrics["_os"].toLowerCase()])
params.qstring.metrics["_os_version"] = os_mapping[params.qstring.metrics["_os"].toLowerCase()] + params.qstring.metrics["_os_version"];
else
params.qstring.metrics["_os_version"] = params.qstring.metrics["_os"][0].toLowerCase() + params.qstring.metrics["_os_version"];
}

} catch (SyntaxError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@
countlyDeviceDetails.fixOSVersion = function(osName) {
return osName
.replace(/:/g, ".")
.replace(/^unk/g, "Unknown ")
.replace(/^qnx/g, "QNX ")
.replace(/^os2/g, "OS/2 ")
.replace(/^mw/g, "Windows ")
.replace(/^ob/g, "Open BSD ")
.replace(/^sb/g, "SearchBot ")
.replace(/^so/g, "Sun OS ")
.replace(/^bo/g, "BeOS ")
.replace(/^l/g, "Linux ")
.replace(/^u/g, "UNIX ")
.replace(/^i/g, "iOS ")
.replace(/^a/g, "Android ")
.replace(/^b/g, "BlackBerry ")
Expand Down

0 comments on commit 341539a

Please sign in to comment.