<commit_before>/**
 * Gets the repositories of the user from Github
 */

import request from 'utils/request';
import { takeLatest } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';
import papaparse from 'papaparse';
import { UPLOAD_PRODUCT_TEMPLATE_FILE } from './constants';
import {
  submitProductImport,
  submitProductImportSuccess,
  submitProductImportDataError,
  submitProductImportFileError,
} from './actions';
import { selectCsvData } from './selectors';

function readCsv(file) {
  const deferred = {};
  deferred.promise = new Promise((resolve, reject) => {
    deferred.resolve = resolve;
    deferred.reject = reject;
  });
  const papaConfig = {
    complete: (results) => {
      deferred.resolve(results.data);
    },
  };
  papaparse.parse(file, papaConfig);
  return deferred.promise;
}

export function* submitImport() {
  const csvData = yield select(selectCsvData());
  const requestURL = 'http://api.teamruah.com/v1/product/csvBatchCreate';

  const data = yield readCsv(csvData);<commit_msg>Massive file check on product import<commit_after>/**
 * Gets the repositories of the user from Github
 */

import request from 'utils/request';
import { takeLatest } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';
import papaparse from 'papaparse';
import { UPLOAD_PRODUCT_TEMPLATE_FILE } from './constants';
import {
  submitProductImport,
  submitProductImportSuccess,
  submitProductImportDataError,
  submitProductImportFileError,
} from './actions';
import { selectCsvData } from './selectors';

function readCsv(file) {
  const deferred = {};
  deferred.promise = new Promise((resolve, reject) => {
    deferred.resolve = resolve;
    deferred.reject = reject;
  });
  const papaConfig = {
    complete: (results) => {
      deferred.resolve(results.data);
    },
  };
  papaparse.parse(file, papaConfig);
  return deferred.promise;
}

export function* submitImport() {
  const csvData = yield select(selectCsvData());
  const requestURL = 'http://api.teamruah.com/v1/product/csvBatchCreate';

  const data = yield readCsv(csvData);
  if (data.length > 5000) {
    yield put(submitProductImportFileError(`This file exceeds the limit for a single product upload. There were ${data.length} rows read from this file. If that number is not consistent with what appears in your spreadsheet application, make sure that your CSV file has no trailing blank rows.`));
    return;
  }
{'fraction_non_alphanumeric': 0.11668706650346797, 'fraction_numerical': 0.0024479804161566705, 'mean_word_length': 4.41280353200883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2126848', 'n_tokens_mistral': 753, 'n_tokens_neox': 739, 'n_words': 205}