summaryrefslogtreecommitdiff
path: root/service_telemetry.js
blob: 7dfac51cced8afdfdc968421cad199090d9fb1a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 || "telesuck",
    SAMPLE_TOURNAMENT_QUEUE = process.env.SAMPLE_TOURNAMENT_QUEUE || "telesuck_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);
            }
        });
    }
}