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K,KACzC,MAAM,EAAS,EAAI,OACb,EAAS,MAAM,YACf,EAAM,GAAG,EAAO,UAAU,EAAO,MAEvC,OADA,EAAI,UAAU,eAAgB,OAAO,MAC9B,MACL,KAAK,EAAQ,GACb,MAAK,GAAO,EAAI,IAAI,IAAI,OAAO,EAAK,aACpC,MAAM,EAAK,IAId,IAAI,KAAI,CAAC,EAAK,EAAK,EAAK,KACnB,aAAe,QAAQ,eAC1B,EAAI,OAAS,KAEd,EAAK,EAAI,IAIV,IAAI,KAAI,CAAC,EAAK,EAAK,KAClB,IAAI,EAAM,IAAI,MAAM,aACpB,EAAI,OAAS,IACb,EAAK,EAAI,IAIV,IAAI,KAAI,CAAC,EAAK,EAAK,EAAK,KACW,MAA9B,EAAE,IAAI,EAAK,SAAU,KACxB,OAAO,KAAK,GAAG,EAAI,YAAY,EAAI,aAAa,EAAI,eAEpD,OAAO,MAAM,GAGd,EAAI,OAAO,EAAI,QAAU,KAEpB,EAAI,YAIR,EAAI,OAHJ,EAAI,UAAU,eAAgB,cAC9B,EAAI,KAAK,CAAC,MAAO,EAAI,UAGtB,IAGD,OAAO,OAAO,OAAO,MAAM,KAC1B,OAAO,KAAK,+BAA+B,OAAO,aAAa","file":"/npm/jsperf-img-svc@0.1.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/jsperf-img-svc@0.1.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst\n\tlogger = require('./lib/logger');\n\nconst\n\t_ = require('lodash'),\n\tpath = require('path'),\n\thttp = require('http'),\n\tfs = require('fs-extra'),\n\texpress = require('express'),\n\thighland = require('highland'),\n\tPromise = require('bluebird'),\n\tconfig = require('./lib/config'),\n\tcache = require('./lib/cache'),\n\tshared = require('./lib/shared'),\n\tTestCase = require('./lib/test-case'),\n\tSVGStream = require('./lib/svg-stream'),\n\twinston = require('winston');\n\nconst\n\tapp = express(),\n\tserver = http.createServer(app);\n\n// app config\napp.set('x-powered-by', false);\n\n// static files\napp.use('/public', express.static(path.join(__dirname, 'public')));\n\n// service endpoint\napp.get('/:slug/:rev?', (req, res, next) => {\n\tconst query = req.query;\n\tconst params = req.params;\n\tconst client = cache.getClient();\n\tif (/\\.[a-z0-9]+$/i.test(params.slug)) {\n\t\t// continue if this is a request for a static asset\n\t\tnext();\n\t} else {\n\t\tlet testCase = new TestCase(params.slug, params.rev);\n\t\ttestCase\n\t\t\t.fetch()\n\t\t\t.then(() => {\n\t\t\t\tswitch (query.o) {\n\t\t\t\t\tcase 'json':\n\t\t\t\t\t\treturn res.json(testCase);\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn cache\n\t\t\t\t\t\t\t.expired(client, testCase.imageKey)\n\t\t\t\t\t\t\t.then(() => {\n\t\t\t\t\t\t\t\treq.url = testCase.image;\n\t\t\t\t\t\t\t\tnext();\n\t\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((err) => {\n\t\t\t\tif (err.code != 'ENOTCACHED') {\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t\treturn SVGStream(testCase.link)\n\t\t\t\t\t.pipe(highland())\n\t\t\t\t\t.through(shared.streamToPromise)\n\t\t\t\t\t.then((bufferArray) => {\n\t\t\t\t\t\tlet buffer = shared.joinBuffer(bufferArray);\n\t\t\t\t\t\tres.setHeader('Content-Type', config.mime);\n\t\t\t\t\t\tres.end(buffer);\n\t\t\t\t\t\treturn cache.write(client, testCase.imageKey, buffer.toString('base64'), config.imageTTL);\n\t\t\t\t\t});\n\t\t\t})\n\t\t\t.then(() => logger.info(`200 ${req.originalUrl}`))\n\t\t\t.timeout(config.timeout)\n\t\t\t.catch(next);\n\t}\n});\n\n// cache endpoint\napp.get('/cache/:prefix/:tag', (req, res, next) => {\n\tconst params = req.params;\n\tconst client = cache.getClient();\n\tconst key = `${params.prefix}:${params.tag}`;\n\tres.setHeader('Content-Type', config.mime);\n\treturn cache\n\t\t.read(client, key)\n\t\t.then(str => res.end(new Buffer(str, 'base64')))\n\t\t.catch(next);\n});\n\n// handle timeout\napp.use((err, req, res, next) => {\n\tif (err instanceof Promise.TimeoutError) {\n\t\terr.status = 408;\n\t}\n\tnext(err);\n});\n\n// catch 404 and forward to error handler\napp.use((req, res, next) => {\n\tvar err = new Error('Not Found');\n\terr.status = 404;\n\tnext(err);\n});\n\n// handle errors\napp.use((err, req, res, next) => {\n\tif (_.get(err, 'status', 500) !== 500) {\n\t\tlogger.warn(`${err.status} | ${err.message} | ${req.originalUrl}`);\n\t} else {\n\t\tlogger.error(err);\n\t}\n\n\tres.status(err.status || 500);\n\n\tif (!res.headersSent) {\n\t\tres.setHeader('Content-Type', 'text/plain');\n\t\tres.json({error: err.message});\n\t} else {\n\t\tres.end();\n\t}\n});\n\nserver.listen(config.port, () => {\n\tlogger.info(`jsperf service listening at ${config.localBase}.`);\n});\n"]}