From dd6c4c39440982e2943906f2fa30dbbb8260540b Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 14 Jul 2017 18:56:30 +0200 Subject: 2.14.0 rewrite: modularization --- service_telemetry.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 service_telemetry.js (limited to 'service_telemetry.js') diff --git a/service_telemetry.js b/service_telemetry.js new file mode 100644 index 0000000..285de4e --- /dev/null +++ b/service_telemetry.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node +/* jshint esnext: true */ +"use strict"; + +const Promise = require("bluebird"), + Service = require("./service_skeleton.js"); + +const logger = global.logger, + SAMPLE_QUEUE = process.env.SAMPLE_QUEUE || "sample", + SAMPLE_TOURNAMENT_QUEUE = process.env.SAMPLE_TOURNAMENT_QUEUE || "sample_tournament"; + +module.exports = class Analyzer extends Service { + constructor() { + super(); + + this.setTargets({ + "regular": SAMPLE_QUEUE, + "tournament": SAMPLE_TOURNAMENT_QUEUE + }); + + this.setRoutes({ + "/api/match/:match/telemetry/:category?": async (req, res) => { + logger.info("requesting download for Telemetry", { api_id: req.params.match }); + const category = req.params.category || "regular", + db = this.getDatabase(category), + asset = await db.Asset.findOne({ where: { + match_api_id: req.params.match + } }); + if (asset == undefined) { + logger.error("could not find any assets for match", + { api_id: req.params.match }); + res.sendStatus(404); + return; + } + await this.forward(this.getTarget(category), asset.url, { + persistent: true, + headers: { match_api_id: req.params.match } + }); + res.sendStatus(204); + } + }); + } +} -- cgit v1.3.1