<commit_before>import { pipeline } from "node:stream/promises";
import { asyncHandler } from "../util.js";
import config from "@argos-ci/config";
import { s3 as getS3, get } from "@argos-ci/storage";
import { Router } from "express";

const router = Router();

router.get(
  "/:key",
  asyncHandler(async (req, res) => {
    const s3 = getS3();
    const result = await get({
      s3,
      Bucket: config.get("s3.screenshotsBucket"),
      Key: req.params["key"] as string,
    });
    res.set("Content-Type", result.ContentType);
    if (result.ContentLength != null) {
      res.set("Content-Length", String(result.ContentLength));
    }
    res.set("Cache-Control", "public, max-age=31536000, immutable");
    await pipeline(result.Body, res);
  })
);

export { router as screenshots };
<commit_msg>perf(screenshot): redirect instead of stream from S3<commit_after>import { asyncHandler } from "../util.js";
import config from "@argos-ci/config";
import { s3 as getS3, getSignedGetObjectUrl } from "@argos-ci/storage";
import { Router } from "express";

const router = Router();

router.get(
  "/:key",
  asyncHandler(async (req, res) => {
    const s3 = getS3();
    const url = await getSignedGetObjectUrl({
      s3,
      Bucket: config.get("s3.screenshotsBucket"),
      Key: req.params["key"] as string,
      expiresIn: 3600,
    });
    res.redirect(url);
  })
);

export { router as screenshots };

{'fraction_non_alphanumeric': 0.16147308781869688, 'fraction_numerical': 0.017705382436260624, 'mean_word_length': 3.5876623376623376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4528658', 'n_tokens_mistral': 480, 'n_tokens_neox': 466, 'n_words': 117}