<commit_before>'use strict';
var Observable = require('../utils').Observable,
    metrics = require('../metrics'),
    metricPrefix = 'timer.bin.',
    crypto = require('crypto');

var model = {
  constructor: function BinModel(store) {
    Observable.call(this);
    this.store = store;
  },
  load: function (params, fn) {
    this.store.getBin(params, function loadedGetBin(err, bin) {
      if (err || !bin) {
        return fn(err);
      }

      this.getBinMetadata(bin, function loadBinMetadata(err, binMetadata) {
        if (err) {
          return fn(err);
        }

        bin.metadata = binMetadata;

        if (this.isVisible(bin, params.username)) {
          fn(null, bin);
        } else {
          fn(401);
        }
      }.bind(this));
    }.bind(this));
  },
  isVisible: function (bin, username) {
    if (!bin.metadata) { // bin does not exist yet, it cannot be private
      return true;
    }
    // this should only let users see the latest
    // "active", and visible bin to that user
    if (bin && bin.active === 'y') {
      if (bin.metadata.visibility === 'public') {
        return true;
      }
      if (username && bin.metadata.name === username) {
        return true;
      }
    }

    return false;
  },
  latest: function (params, fn) {
    this.store.getLatestBin(params, function loadedGetLatestBin(err, bin) {
      if (err || !bin) {
        return fn(err, null);
      }

      this.getBinMetadata(bin, function loadedGetMetadata(err, metadata) {
        bin.metadata = metadata;

        if (this.isVisible(bin, params.username)) {<commit_msg>Explaining why we check for no metadata<commit_after>'use strict';
var Observable = require('../utils').Observable,
    metrics = require('../metrics'),
    metricPrefix = 'timer.bin.',
    crypto = require('crypto');

var model = {
  constructor: function BinModel(store) {
    Observable.call(this);
    this.store = store;
  },
  load: function (params, fn) {
    this.store.getBin(params, function loadedGetBin(err, bin) {
      if (err || !bin) {
        return fn(err);
      }

      this.getBinMetadata(bin, function loadBinMetadata(err, binMetadata) {
        if (err) {
          return fn(err);
        }

        bin.metadata = binMetadata;

        if (this.isVisible(bin, params.username)) {
          fn(null, bin);
        } else {
          fn(401);
        }
      }.bind(this));
    }.bind(this));
  },
  isVisible: function (bin, username) {
    // This will only occur if it isn't a real bin, it has been created
    // on from default files and does not exist in any database. By this
    // logic the bin must be public, it has no owner and no record.
    if (!bin.metadata) {
      return true;
    }
    // this should only let users see the latest
    // "active", and visible bin to that user
    if (bin && bin.active === 'y') {
      if (bin.metadata.visibility === 'public') {
        return true;
      }
      if (username && bin.metadata.name === username) {
        return true;
      }
    }

    return false;
  },
  latest: function (params, fn) {
    this.store.getLatestBin(params, function loadedGetLatestBin(err, bin) {
      if (err || !bin) {
        return fn(err, null);
      }

      this.getBinMetadata(bin, function loadedGetMetadata(err, metadata) {
        bin.metadata = metadata;

        if (this.isVisible(bin, params.username)) {
{'fraction_non_alphanumeric': 0.13672684226102397, 'fraction_numerical': 0.0017756732761171944, 'mean_word_length': 2.2751937984496124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6841004', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1002, 'n_words': 284}