<commit_before>import 'whatwg-fetch';
import Attachment from '../models/Attachment';

export default class AttachmentFetcher {

  static fetchThumbnail(params) {
    let promise = fetch(`/api/v1/attachments/thumbnail/${params.id}`, {
      credentials: 'same-origin',
      method: 'GET'
    }).then((response) => {
      return response.json()
    }).then((json) => {
      return json
    }).catch((errorMessage) => {
      console.log(errorMessage);
    });

    return promise;
  }

  static fetchThumbnails(ids) {
    let promise = fetch('/api/v1/attachments/thumbnails/', {
      credentials: 'same-origin',
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ ids }),
    }).then((response) => {
      return response.json();
    }).then((json) => {
      return json;
    }).catch((errorMessage) => {
      console.log(errorMessage);
    });

    return promise;
  }

  static getFileListfrom(container){
    var allFiles = new Array();
    this.filterAllAttachments(allFiles, container.children);
    return allFiles
  }

  static filterAllAttachments(files, containers){

    containers.forEach( (container) => {
      const fileFromAttachment = function(attachment) {
        let file = attachment.file;
        file.id = attachment.id;
        file.container_id = container.id;
        return file;
      }
      var tmpArray = container.attachments.filter(a => a.is_new).map(a => fileFromAttachment(a));
      files.push.apply(files, tmpArray)<commit_msg>Report LSDF - FE: fetcher<commit_after>import 'whatwg-fetch';
import Attachment from '../models/Attachment';

export default class AttachmentFetcher {

  static fetchThumbnail(params) {
    let promise = fetch(`/api/v1/attachments/thumbnail/${params.id}`, {
      credentials: 'same-origin',
      method: 'GET'
    }).then((response) => {
      return response.json()
    }).then((json) => {
      return json
    }).catch((errorMessage) => {
      console.log(errorMessage);
    });

    return promise;
  }

  static fetchThumbnails(ids) {
    let promise = fetch('/api/v1/attachments/thumbnails/', {
      credentials: 'same-origin',
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ ids }),
    }).then((response) => {
      return response.json();
    }).then((json) => {
      return json;
    }).catch((errorMessage) => {
      console.log(errorMessage);
    });

    return promise;
  }

  static getFileListfrom(container){
    var allFiles = new Array();
    this.filterAllAttachments(allFiles, container.children);
    return allFiles
  }

  static filterAllAttachments(files, containers){

    containers.forEach( (container) => {
      const fileFromAttachment = function(attachment) {
        let file = attachment.file;
        file.id = attachment.id;
        file.attachable_id = container.id;
        file.attachable_type = 'Container';
        return file;
      }
      var tmpArray = container.attachments.filter(a => a.is_new).map(a => fileFromAttachment(a));
      files.push.apply(files, tmpArray)
{'fraction_non_alphanumeric': 0.14758190327613105, 'fraction_numerical': 0.0012480499219968799, 'mean_word_length': 2.8257756563245824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4939081', 'n_tokens_mistral': 954, 'n_tokens_neox': 953, 'n_words': 184}