<commit_before>part of model;

class FilesModel {
  final Logger _log = new Logger('FilesModel');
  
  FilesModel(): super() {
  }
  
  Future<int> updateFile(int id, mysql.Transaction tran, {List<String> tags: null, String name: null}) { 
    this._log.info("Update requested for file ${id}");
    
    
    return this.setTags(id, tags, tran); 
  }
  
  static const String _DELETE_TAGS_SQL = "DELETE FROM tags WHERE image = ?";
  static const String _SET_TAGS_SQL = "INSERT INTO tags (image,tag) VALUES (?,?)";
  
  Future setTags(int id, List<String> tags, mysql.Transaction transaction) {
    this._log.info("Setting tags for file ${id}");
    return new Future.sync(() {
      if(tags==null||tags.length==0) {
        return null;
      }
      return transaction.prepare(_DELETE_TAGS_SQL);
    }).then((mysql.Query query) {
      if(query==null) {
        return null;
      }
      return query.execute([id]).then((_) {
        return transaction.prepare(_SET_TAGS_SQL);
      }).then((mysql.Query  t_query) {
        List args = new List();
        for(String tag in tags) {
          if(tag!=null&&tag!="") {
            args.add([id,tag]);
          }
        }
        return t_query.executeMulti(args).then((_) {
          t_query.close();
        });
      }).then((_) {
        query.close();
      });
    });
  }
  
  Future<int> createFile(List<int> data, List<String> tags, mysql.Transaction tran, {String name: null, ContentType ct: null}) {
    this._log.info("Creating file");
    return new Future.sync(() {
      // Verify submitted mime type
      if(data.length >= mime.defaultMagicNumbersMaxLength) {
        String mime_str = mime.lookupMimeType("genericfilename",
            headerBytes: data.sublist(0,mime.defaultMagicNumbersMaxLength));
        
        if(mime_str==null) {
          this._log.warning("No mime type for uploaded data!");
          if(ct==null) {
            throw new Exception("Could not determine MIME type of file, and no content type was provided in submitted data");
          }
          mime_str = ct.toString();
        } else {
          ContentType type = ContentType.parse(mime_str);
          this._log.warning("Uploaded data claims to be ${ct}, but validation says it's ${mime_str}");
        }
        <commit_msg>started c reating staging stuff<commit_after>part of model;

class FilesModel {
  final Logger _log = new Logger('FilesModel');
  
  FilesModel(): super() {
  }
  
  Future<int> updateFile(int id, mysql.Transaction tran, {List<String> tags: null, String name: null}) { 
    this._log.info("Update requested for file ${id}");
    
    
    return this.setTags(id, tags, tran); 
  }
  
  static const String _DELETE_TAGS_SQL = "DELETE FROM tags WHERE image = ?";
  static const String _SET_TAGS_SQL = "INSERT INTO tags (image,tag) VALUES (?,?)";
  
  Future setTags(int id, List<String> tags, mysql.Transaction transaction) {
    this._log.info("Setting tags for file ${id}");
    return new Future.sync(() {
      if(tags==null||tags.length==0) {
        return null;
      }
      return transaction.prepare(_DELETE_TAGS_SQL);
    }).then((mysql.Query query) {
      if(query==null) {
        return null;
      }
      return query.execute([id]).then((_) {
        return transaction.prepare(_SET_TAGS_SQL);
      }).then((mysql.Query  t_query) {
        List args = new List();
        for(String tag in tags) {
          if(tag!=null&&tag!="") {
            args.add([id,tag]);
          }
        }
        return t_query.executeMulti(args).then((_) {
          t_query.close();
        });
      }).then((_) {
        query.close();
      });
    });
  }
  
  Future<int> stageFile(List<int> data, List<String> tags, mysql.Transaction tran, {String name: null, ContentType ct: null}) {
    this._log.info("Creating file");
    return new Future.sync(() {
      // Verify submitted mime type
      if(data.length >= mime.defaultMagicNumbersMaxLength) {
        String mime_str = mime.lookupMimeType("genericfilename",
            headerBytes: data.sublist(0,mime.defaultMagicNumbersMaxLength));
        
        if(mime_str==null) {
          this._log.warning("No mime type for uploaded data!");
          if(ct==null) {
            throw new Exception("Could not determine MIME type of file, and no content type was provided in submitted data");
          }
          mime_str = ct.toString();
        } else {
          ContentType type = ContentType.parse(mime_str);
          this._log.warning("Uploaded data claims to be ${ct}, but validation says it's ${mime_str}");
        }
        
{'fraction_non_alphanumeric': 0.1355191256830601, 'fraction_numerical': 0.0008743169398907104, 'mean_word_length': 2.522709776751347, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '7190166', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1351, 'n_words': 340}