<commit_before>angular.module('Directory.audioFiles.models', ['RailsModel', 'S3Upload'])
.factory('AudioFile', ['$window', 'Model', 'S3Upload', '$http', function ($window, Model, S3Upload, $http) {
  var AudioFile = Model({url:'/api/items/{{itemId}}/audio_files/{{id}}', name: 'audio_file', only: ['url', 'filename']});

  AudioFile.transcribeRatePerMinute = 2;

  AudioFile.prototype.cleanFileName = function (fileName) {
    return fileName.replace(/[^a-z0-9\.]+/gi,'_');
  }

  AudioFile.prototype.uploadKey = function (token, fileName) {
    return (token + '/' + this.cleanFileName(fileName));
  }

  AudioFile.prototype.getStorage = function () {
    var self = this;
    return AudioFile.processResponse($http.get(self.$url() + '/upload_to')).then(function (storage) {
      self.storage = storage;
      return self.storage;
    });
  }

  AudioFile.prototype.upload = function (file, options) {
    var self = this;
    self.getStorage().then(function (storage) {
      // console.log('upload_to!', storage, self, self.storage);

      options = options || {};

      options.bucket     = options.bucket       || self.storage.bucket;
      options.access_key = options.access_key   || self.storage.key;
      options.ajax_base  = self.$url();
      options.key        = self.uploadKey(options.token, file.name);
      options.file       = file;

      self.upload = new S3Upload(options);
      self.upload.upload();
    });
  };

 
  AudioFile.prototype.canOrderTranscript = function (user) {
    var self = this;
    if (!self.transcodedAt) return false;
 
    if (!user.isAdmin()) return false;

    // if (user.plan && user.plan == 'community') return false;

    var t = self.taskForType('order_transcript');
    if (t) return false;

    return true;
  };

  AudioFile.prototype.isTranscriptOrdered = function () {
    var self = this;
    var t = self.taskForType('order_transcript');
    if (t && t.status != 'complete') {
      return true;
    }
    return false;      
  }

  AudioFile.prototype.canSendToAmara = function (user) {
    var self = this;

    if (!self.canOrderTranscript(user)) return false;

    console.log('canSendToAmara', user.organization);
    if (!user.organization || !user.organization.amaraTeam) return false;

    return true;
  };

  AudioFile.prototype.taskForType = function (t) {
    for(var i = 0; i < this.tasks.length; i++) {<commit_msg>limit transcripts to non-community plans<commit_after>angular.module('Directory.audioFiles.models', ['RailsModel', 'S3Upload'])
.factory('AudioFile', ['$window', 'Model', 'S3Upload', '$http', function ($window, Model, S3Upload, $http) {
  var AudioFile = Model({url:'/api/items/{{itemId}}/audio_files/{{id}}', name: 'audio_file', only: ['url', 'filename']});

  AudioFile.transcribeRatePerMinute = 2;

  AudioFile.prototype.cleanFileName = function (fileName) {
    return fileName.replace(/[^a-z0-9\.]+/gi,'_');
  }

  AudioFile.prototype.uploadKey = function (token, fileName) {
    return (token + '/' + this.cleanFileName(fileName));
  }

  AudioFile.prototype.getStorage = function () {
    var self = this;
    return AudioFile.processResponse($http.get(self.$url() + '/upload_to')).then(function (storage) {
      self.storage = storage;
      return self.storage;
    });
  }

  AudioFile.prototype.upload = function (file, options) {
    var self = this;
    self.getStorage().then(function (storage) {
      // console.log('upload_to!', storage, self, self.storage);

      options = options || {};

      options.bucket     = options.bucket       || self.storage.bucket;
      options.access_key = options.access_key   || self.storage.key;
      options.ajax_base  = self.$url();
      options.key        = self.uploadKey(options.token, file.name);
      options.file       = file;

      self.upload = new S3Upload(options);
      self.upload.upload();
    });
  };

 
  AudioFile.prototype.canOrderTranscript = function (user) {
    var self = this;
    if (!self.transcodedAt) return false;
 
    if (!user.isAdmin()) return false;

    if (user.plan && user.plan == 'community') return false;

    var t = self.taskForType('order_transcript');
    if (t) return false;

    return true;
  };

  AudioFile.prototype.isTranscriptOrdered = function () {
    var self = this;
    var t = self.taskForType('order_transcript');
    if (t && t.status != 'complete') {
      return true;
    }
    return false;      
  }

  AudioFile.prototype.canSendToAmara = function (user) {
    var self = this;

    if (!self.canOrderTranscript(user)) return false;

    console.log('canSendToAmara', user.organization);
    if (!user.organization || !user.organization.amaraTeam) return false;

    return true;
  };

  AudioFile.prototype.taskForType = function (t) {
    for(var i = 0; i < this.tasks.length; i++) {
{'fraction_non_alphanumeric': 0.15709529754473575, 'fraction_numerical': 0.0033291718684977114, 'mean_word_length': 3.2352422907488987, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5440913', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1479, 'n_words': 310}