%PDF- %PDF-
Direktori : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/answers/lib/ |
Current File : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/answers/lib/answers.js |
function getParamsFromRequest(n){var t={},i;return n&&(n.headers&&("x-bm-devicedimensions"in n.headers?t.viewDimension=n.headers["x-bm-devicedimensions"]:console.warn("%s: Request is missing x-bm-devicedimensions.",tag),"x-bm-devicescale"in n.headers?t.viewScale=n.headers["x-bm-devicescale"]:console.warn("%s: Request is missing x-bm-devicescale.",tag),"x-bm-devicedimensionslogical"in n.headers?t.viewDimensionsLogical=n.headers["x-bm-devicedimensionslogical"]:console.warn("%s: Request is missing x-bm-devicedimensionslogical.",tag),"x-bm-theme"in n.headers?t.viewTheme=n.headers["x-bm-theme"]:console.warn("%s: Request is missing x-bm-theme.",tag),"x-device-clientsession"in n.headers?t.clientSessionId=n.headers["x-device-clientsession"]:console.warn("%s: Request is missing x-device-clientsession.",tag)),i=url.parse(n.url,!0),i&&i.query?(i.query.form?t.appFormCode=i.query.form:console.warn("%s: Request query is missing form code. ",tag),i.query.refresh==="1"&&(t.shouldRefresh=!0),i.query.topid&&(t.topId=i.query.topid,console.log("%s: TopId is [%s]",tag,t.topId))):console.log("%s: Url is missing query object. ",tag)),t}function instrumentResponse(n,t){n.on("close",function(){t.stop(new Error("ConnectionClosed"))});n.on("finish",function(){t.stop(answersRefresh.lastError,{httpStatus:n.statusCode})})}var events=require("events"),url=require("url"),tag="answers/answers.js",answersRefresh=new events.EventEmitter;answersRefresh.lastResults=null;answersRefresh.lastError=null;answersRefresh.inProgress=!1;answersRefresh.start=function(){answersRefresh.lastError=null;answersRefresh.lastResults=null;answersRefresh.inProgress=!0;answersRefresh.emit("start")};answersRefresh.done=function(n,t){answersRefresh.lastResults=t;answersRefresh.lastError=n;answersRefresh.inProgress=!1;answersRefresh.emit("done",n,t)};var telemetry=require("proactive-telemetry"),telemetryInstance=telemetry.getProactiveTelemetryInstance(),telemetryEvents=telemetry.Events.Answers;exports.start=function(n,t){console.log("%s: adding GET handler for [/proactive*]",tag);n.get("/proactive*",function(n,i){console.log("%s: Handling GET request for [%d]",tag,n.__reqId);answersRefresh.start();var r=getParamsFromRequest(n),u=telemetryInstance.startActivity(telemetryEvents.GetProactiveActivity,{form:r.appFormCode,topId:r.topId||""});instrumentResponse(i,u);t.getAnswers(r,i,function(n,t){if(n){console.error("Error in GetAnswers: ",n);answersRefresh.done(n);var r=500;n.name=="NoConnectionError"?r=503:n.name=="RequestTimeoutError"?r=504:n.name=="InvalidResponseError"&&(r=520);i.writeHead(r,{"Content-Type":"text/html"});i.end()}return answersRefresh.done(null,t)})});console.log("%s: adding GET handler for [/answers*]",tag);n.get("/answers*",function(n,t){console.log("%s: Handling GET request for [%d]",tag,n.__reqId);var r=telemetryInstance.startActivity(telemetryEvents.GetAnswersActivity);if(instrumentResponse(t,r),n.headers&&n.headers.accept=="application/json"){function i(n,i){if(n){t.writeHead(500,{"Content-Type":"application/json"});var r={name:n.toString(),hr:n.HRESULT,stack:telemetry.getErrorStackForLogging(n)};return t.end(JSON.stringify(r))}return t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify(i))}if(answersRefresh.inProgress)answersRefresh.once("done",i);else i(answersRefresh.lastError,answersRefresh.lastResults)}else return t.writeHead(500,{"Content-Type":"text/html"}),t.end("Only supported content type is application/json")});console.log("%s: adding DELETE handler for [/answers*]",tag);n.delete("/answers*",function(n,i){console.log("%s: Handling DELETE request for [%d]",tag,n.__reqId);var r=telemetryInstance.startActivity(telemetryEvents.DeleteAnswersActivity);instrumentResponse(i,r);t.deleteAnswers(function(n){return n?(console.error("Error in DeleteAnswers: ",n),i.writeHead(500),i.end()):(i.writeHead(200),i.end())})})}