<commit_before>const router = require("koa-router")();
const dropzones = require("../dropzones");
var {execSync} = require("child_process");

var gitRev = execSync("git rev-parse HEAD")
    .toString()
    .trim();

const YEAR = 1000 * 60 * 60 * 24 * 365;

const h2pushJSON = path => `<${path}>; rel=preload; as=fetch`;
const h2pushJS = path => `<${path}>; rel=preload; as=script`;

const pushStaticAssets = (ctx, next) => {
    // "Cache aware" push hack
    // Http2 pushing will skip browser caches so push the assets only
    // when we are sure that it's not in cache
    if (ctx.cookies.get("h2push") !== gitRev) {
        ctx.cookies.set("h2push", gitRev, {maxAge: YEAR});
        ctx.append("Link", h2pushJS("/dist/bundle.js"));
        ctx.append("Link", h2pushJS("/vendor/tracker.js"));
    }
    next();
};

router.get("/", pushStaticAssets);
router.get("/dz/:dz", pushStaticAssets);

router.get("/dz/:dz", (ctx, next) => {
    // Weather data needs to be always fresh so always push it
    const dz = dropzones[ctx.params.dz.toUpperCase()];
    if (!dz) return next();

    [
        `/api/observations/${dz.fmisid}/fi-1-1-windgust`,
        `/api/observations/${dz.fmisid}/fi-1-1-windspeedms`,
        `/api/forecasts/${dz.lat},${dz.lon}/enn-s-1-1-windgust`,
        `/api/forecasts/${dz.lat},${dz.lon}/enn-s-1-1-windspeedms`,
        `/api/metars/${dz.icaocode}`,
    ].forEach(path => {
        ctx.append("Link", h2pushJSON(path));
    });

    next();
});

module.exports = router;
<commit_msg>push tracker first<commit_after>const router = require("koa-router")();
const dropzones = require("../dropzones");
var {execSync} = require("child_process");

var gitRev = execSync("git rev-parse HEAD")
    .toString()
    .trim();

const YEAR = 1000 * 60 * 60 * 24 * 365;

const h2pushJSON = path => `<${path}>; rel=preload; as=fetch`;
const h2pushJS = path => `<${path}>; rel=preload; as=script`;

const pushStaticAssets = (ctx, next) => {
    // "Cache aware" push hack
    // Http2 pushing will skip browser caches so push the assets only
    // when we are sure that it's not in cache
    if (ctx.cookies.get("h2push") !== gitRev) {
        ctx.cookies.set("h2push", gitRev, {maxAge: YEAR});
        ctx.append("Link", h2pushJS("/vendor/tracker.js"));
        ctx.append("Link", h2pushJS("/dist/bundle.js"));
    }
    next();
};

router.get("/", pushStaticAssets);
router.get("/dz/:dz", pushStaticAssets);

router.get("/dz/:dz", (ctx, next) => {
    // Weather data needs to be always fresh so always push it
    const dz = dropzones[ctx.params.dz.toUpperCase()];
    if (!dz) return next();

    [
        `/api/observations/${dz.fmisid}/fi-1-1-windgust`,
        `/api/observations/${dz.fmisid}/fi-1-1-windspeedms`,
        `/api/forecasts/${dz.lat},${dz.lon}/enn-s-1-1-windgust`,
        `/api/forecasts/${dz.lat},${dz.lon}/enn-s-1-1-windspeedms`,
        `/api/metars/${dz.icaocode}`,
    ].forEach(path => {
        ctx.append("Link", h2pushJSON(path));
    });

    next();
});

module.exports = router;

{'fraction_non_alphanumeric': 0.2028410967955071, 'fraction_numerical': 0.0191608853650479, 'mean_word_length': 3.1197278911564625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1152368', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1090, 'n_words': 224}