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017 European Digital Reading Lab. All rights reserved.\n// Licensed to the Readium Foundation under one or more contributor license agreements.\n// Use of this source code is governed by a BSD-style license\n// that can be found in the LICENSE file exposed on Github (readium) in the project repository.\n// ==LICENSE-END==\n\nimport * as crypto from \"crypto\";\nimport * as css2json from \"css2json\";\nimport * as debug_ from \"debug\";\nimport * as express from \"express\";\nimport * as fs from \"fs\";\nimport * as jsonMarkup from \"json-markup\";\nimport * as path from \"path\";\n\nimport {\n IRequestPayloadExtension, IRequestQueryParams, _jsonPath, _show, _urlEncoded,\n} from \"./request-ext\";\nimport { Server } from \"./server\";\n\nconst debug = debug_(\"r2:streamer#http/server-version\");\n\n// https://github.com/mafintosh/json-markup/blob/master/style.css\nconst jsonStyle = `\n.json-markup {\n line-height: 17px;\n font-size: 13px;\n font-family: monospace;\n white-space: pre;\n}\n.json-markup-key {\n font-weight: bold;\n}\n.json-markup-bool {\n color: firebrick;\n}\n.json-markup-string {\n color: green;\n}\n.json-markup-null {\n color: gray;\n}\n.json-markup-number {\n color: blue;\n}\n`;\n\n// tslint:disable-next-line:variable-name\nexport const serverVersion_PATH = \"/version\";\nexport function serverVersion(server: Server, topRouter: express.Application) {\n\n topRouter.get([serverVersion_PATH, serverVersion_PATH + \"/\" + _show + \"/:\" + _jsonPath + \"?\"],\n (req: express.Request, res: express.Response) => {\n\n const reqparams = (req as IRequestPayloadExtension).params;\n\n const isShow = req.url.indexOf(\"/show\") >= 0 || (req.query as IRequestQueryParams).show;\n if (!reqparams.jsonPath && (req.query as IRequestQueryParams).show) {\n reqparams.jsonPath = (req.query as IRequestQueryParams).show;\n }\n\n const gitRevJson = \"../../../gitrev.json\";\n if (!fs.existsSync(path.resolve(path.join(__dirname, gitRevJson)))) {\n\n const err = \"Missing Git rev JSON! \";\n debug(err + gitRevJson);\n res.status(500).send(\"<html><body><p>Internal Server Error</p><p>\"\n + err + \"</p></body></html>\");\n return;\n }\n\n const jsonObj = require(gitRevJson);\n // debug(jsonObj);\n\n if (isShow) {\n const jsonPretty = jsonMarkup(jsonObj, css2json(jsonStyle));\n\n res.status(200).send(\"<html><body>\" +\n \"<h1>R2-STREAMER-JS VERSION INFO</h1>\" +\n \"<hr><p><pre>\" + jsonPretty + \"</pre></p>\" +\n // \"<hr><p><pre>\" + jsonStr + \"</pre></p>\" +\n // \"<p><pre>\" + dumpStr + \"</pre></p>\" +\n \"</body></html>\");\n } else {\n server.setResponseCORS(res);\n res.set(\"Content-Type\", \"application/json; charset=utf-8\");\n\n const jsonStr = JSON.stringify(jsonObj, null, \" \");\n\n const checkSum = crypto.createHash(\"sha256\");\n checkSum.update(jsonStr);\n const hash = checkSum.digest(\"hex\");\n\n const match = req.header(\"If-None-Match\");\n if (match === hash) {\n debug(\"publications.json cache\");\n res.status(304); // StatusNotModified\n res.end();\n return;\n }\n\n res.setHeader(\"ETag\", hash);\n // server.setResponseCacheHeaders(res, true);\n\n res.status(200).send(jsonStr);\n }\n });\n}\n"]}
\No newline at end of file