<commit_before>var path = require('path');
var fs = require('fs-ext');
var fsExtra = require('fs-extra');
var utils = require('./utils');
var filetype = require('../content/src/filetype');
var filemeta = require('./filemeta');
var DirLoader = require('./dirloader').DirLoader;

var globalDirCache = {};

// Do not serve cached content older than 30 minutes.
var maxDirCacheAge = 30 * 60 * 1000;

// Rebuild cache in background after serving data older than a 2 minutes.
var autoRebuildCacheAge = 2 * 60 * 1000;

// Serve at most 600 entries at a time from root directory or share site.
var MAX_DIR_ENTRIES = 600;

function getDirCache(dir) {
  var dircache = globalDirCache[dir]
  if (!dircache) {
    dircache = new DirLoader(dir);
    globalDirCache[dir] = dircache;
  }
  return dircache;
}

exports.handleLoad = function(req, res, app, format) {
  var filename = utils.filenameFromUri(req) || '';
  var callback = utils.param(req, 'callback');
  var user = res.locals.owner || '';
  var origfilename = filename;
  var prefix = utils.param(req, 'prefix', '');
  var count = Math.min(utils.param(req, 'count', MAX_DIR_ENTRIES),
                       MAX_DIR_ENTRIES);

  try {
    // Check if the request is for root listing or share site.
    var isRootListing = !user && filename === '' && format === 'json';
    var isShareSite = user === 'share' && filename === '' && format === 'json';

    // Validate username
    if (user) {
      utils.validateUserName(user);
      if (filename.length > 0) {
        filename = path.join(user, filename);
      }
      else {
        filename = user + '/';
      }
    }

    // Validate filename
    if (filename.length > 0) {
      if (!utils.isFileNameValid(filename, false)) {
        utils.errorExit('Bad filename: ' + filename);
      }
    }

    var absfile = utils.makeAbsolute(filename, app);

    if (format == 'json') {
      var haskey = userhaskey(user, app);

      // Handle the case of a file that's present<commit_msg>Added gymstage as special account.<commit_after>var path = require('path');
var fs = require('fs-ext');
var fsExtra = require('fs-extra');
var utils = require('./utils');
var filetype = require('../content/src/filetype');
var filemeta = require('./filemeta');
var DirLoader = require('./dirloader').DirLoader;

var globalDirCache = {};

// Do not serve cached content older than 30 minutes.
var maxDirCacheAge = 30 * 60 * 1000;

// Rebuild cache in background after serving data older than a 2 minutes.
var autoRebuildCacheAge = 2 * 60 * 1000;

// Serve at most 600 entries at a time from root directory or share site.
var MAX_DIR_ENTRIES = 600;

// Special share sites
var SHARE_SITE = { share: true, gymstage: true };

function getDirCache(dir) {
  var dircache = globalDirCache[dir]
  if (!dircache) {
    dircache = new DirLoader(dir);
    globalDirCache[dir] = dircache;
  }
  return dircache;
}

exports.handleLoad = function(req, res, app, format) {
  var filename = utils.filenameFromUri(req) || '';
  var callback = utils.param(req, 'callback');
  var user = res.locals.owner || '';
  var origfilename = filename;
  var prefix = utils.param(req, 'prefix', '');
  var count = Math.min(utils.param(req, 'count', MAX_DIR_ENTRIES),
                       MAX_DIR_ENTRIES);

  try {
    // Check if the request is for root listing or share site.
    var isRootListing = !user && filename === '' && format === 'json';
    var isShareSite = SHARE_SITE[user] && filename === '' && format === 'json';

    // Validate username
    if (user) {
      utils.validateUserName(user);
      if (filename.length > 0) {
        filename = path.join(user, filename);
      }
      else {
        filename = user + '/';
      }
    }

    // Validate filename
    if (filename.length > 0) {
      if (!utils.isFileNameValid(filename, false)) {
        utils.errorExit('Bad filename: ' + filename);
      }
    }

    var absfile = utils.makeAbsolute(filename, app);

    if (format == 'json') {
      var haskey = userhaskey(user, app);

      // Handle the case of a file that's present
{'fraction_non_alphanumeric': 0.13968957871396895, 'fraction_numerical': 0.012811037201281104, 'mean_word_length': 3.01980198019802, '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': '4283291', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1240, 'n_words': 375}