<commit_before>const fs = require('fs');
const path = require('path');
const { promisify } = require('util');

const readFile = promisify(fs.readFile);

const projectName = require(path.join(process.cwd(), 'package.json')).name;
const s3Bucket = process.env.ASSETS_S3_BUCKET;

module.exports = () => {
  const queryMap = new Map();
  const assetsBase = s3Bucket ? `${s3Bucket}/${projectName}/assets` : path.resolve('build/assets');

  return async (req, res, next) => {
    if (req.body && req.body.id && !req.body.query) {
      try {
        let queryText = queryMap.get(req.body.id);
        if (!queryText) {
          queryText = await readFile(`${assetsBase}/${req.body.id}.query`);
          queryMap.set(req.body.id, queryText);
        }
        req.body.query = queryText;
      } catch (e) {
        console.error(e);
        throw new Error(e);
      }
    }
    return next();
  };
};<commit_msg>fix readfile<commit_after>const fs = require('fs');
const path = require('path');
const { promisify } = require('util');

const readFile = promisify(fs.readFile);

const projectName = require(path.join(process.cwd(), 'package.json')).name;
const s3Bucket = process.env.ASSETS_S3_BUCKET;

module.exports = () => {
  const queryMap = new Map();
  const assetsBase = s3Bucket ? `${s3Bucket}/${projectName}/assets` : path.resolve('build/assets');

  return async (req, res, next) => {
    if (req.body && req.body.id && !req.body.query) {
      try {
        let queryText = queryMap.get(req.body.id);
        if (!queryText) {
          queryText = await readFile(`${assetsBase}/${req.body.id}.query`, 'utf8');
          queryMap.set(req.body.id, queryText);
        }
        req.body.query = queryText;
      } catch (e) {
        console.error(e);
        throw new Error(e);
      }
    }
    return next();
  };
};
{'fraction_non_alphanumeric': 0.1747945205479452, 'fraction_numerical': 0.004931506849315068, 'mean_word_length': 2.9268817204301074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3931612', 'n_tokens_mistral': 605, 'n_tokens_neox': 607, 'n_words': 120}