<commit_before>/* eslint no-console: off */
const fs = require('fs');
const path = require("path");
const fetch = require('node-fetch'); // not needed for local data
const request = require('request');
// const prettyjson = require('prettyjson');

const validUsers = ['guest', 'mumps'];

const getDataFile = (res, filePath, s3) => {
  if (global.LOCAL_DATA) {
    res.sendFile(path.join(global.LOCAL_DATA_PATH, filePath));
  } else if (s3 === "staging") {
    request(global.REMOTE_DATA_STAGING_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  } else {
    // we deliberately don't ensure that s3===live, as this should be the default
    request(global.REMOTE_DATA_LIVE_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  }
};

const getStaticFile = (res, filePath) => {
  if (global.LOCAL_STATIC) {
    res.sendFile(path.join(global.LOCAL_STATIC_PATH, filePath));
  } else {
    request(global.REMOTE_STATIC_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  }
};

// const fetchS3 = (res, filePath) => {
//   fetch(s3 + filePath)
//     .then((fetchRes) => fetchRes.json())
//     .then((json) => {
//       res.json(json);
//       // if (successMsg) {console.log(successMsg);}
//     })
//     .catch((err) => {
//       // if (errMsg) {console.error(errMsg);}
//       console.error(err);
//     });
// };

const getManifest = (query, res) => {
  if (Object.keys(query).indexOf("user") === -1) {
    res.status(404).send('No user defined');
    return;
  }
  if (validUsers.indexOf(query.user) === -1) {
    res.status(404).send('Invalid user');
    return;
  }
  getDataFile(res, 'manifest_' + query.user + '.json', query.s3);
};

const getSplashImage = (query, res) => {
  getDataFile(res, query.src, query.s3);
};

const getImage = (query, res) => {
  getStaticFile(res, query.src);
};<commit_msg>allow any user for manifest (server)<commit_after>/* eslint no-console: off */
const fs = require('fs');
const path = require("path");
const fetch = require('node-fetch'); // not needed for local data
const request = require('request');
// const prettyjson = require('prettyjson');

// const validUsers = ['guest', 'mumps', 'lassa'];

const getDataFile = (res, filePath, s3) => {
  if (global.LOCAL_DATA) {
    res.sendFile(path.join(global.LOCAL_DATA_PATH, filePath));
  } else if (s3 === "staging") {
    request(global.REMOTE_DATA_STAGING_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  } else {
    // we deliberately don't ensure that s3===live, as this should be the default
    request(global.REMOTE_DATA_LIVE_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  }
};

const getStaticFile = (res, filePath) => {
  if (global.LOCAL_STATIC) {
    res.sendFile(path.join(global.LOCAL_STATIC_PATH, filePath));
  } else {
    request(global.REMOTE_STATIC_BASEURL + filePath).pipe(res);
    /* TODO explore https://www.npmjs.com/package/cached-request */
  }
};

// const fetchS3 = (res, filePath) => {
//   fetch(s3 + filePath)
//     .then((fetchRes) => fetchRes.json())
//     .then((json) => {
//       res.json(json);
//       // if (successMsg) {console.log(successMsg);}
//     })
//     .catch((err) => {
//       // if (errMsg) {console.error(errMsg);}
//       console.error(err);
//     });
// };

const getManifest = (query, res) => {
  if (Object.keys(query).indexOf("user") === -1) {
    res.status(404).send('No user defined');
    return;
  }
  // if (validUsers.indexOf(query.user) === -1) {
  //   res.status(404).send('Invalid user');
  //   return;
  // }
  getDataFile(res, 'manifest_' + query.user + '.json', query.s3);
};

const getSplashImage = (query, res) => {
  getDataFile(res, query.src, query.s3);
};

const getImage = (query, res) => {
  getStaticFile(res, query.src);
};
{'fraction_non_alphanumeric': 0.19262812421105782, 'fraction_numerical': 0.007573844988639233, 'mean_word_length': 3.297180043383948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '1434585', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1355, 'n_words': 268}