<commit_before>import {initialStorage} from "./../data/initialStorage";
import guid from "./guid";

const fs = window.require("fs");
const mkdirp = window.require("mkdirp");
const dialog = window.require('electron').remote.dialog;

export default class File {

    constructor() {
        this.storageFileName = "requesto.json";
        this.storageFilePath = `/Users/${window.process.env.USER}/.requesto/`;
        this.storageFileURL = `${this.storageFilePath}${this.storageFileName}`
        this.initialStorage = initialStorage;
        this.checkStorageHealth = this.checkStorageHealth.bind(this);
        this.createStorageFolder = this.createStorageFolder.bind(this);
        this.createStorageFile = this.createStorageFile.bind(this);
        this.loadStorageFile = this.loadStorageFile.bind(this);
        this.exportStorage = this.exportStorage.bind(this);

    }

    checkStorageHealth(data){
        var storage = JSON.parse(data);
        storage.folders.map(folder => {
            folder.id = guid();

            // folder.items = [];
            // for (var i = 0; i < 10000; i++) {
            //     var request = {}
            //     request.name = "teste " + i;
            //     request.type = "GET";
            //     request.url = "https://api.vod.globosat.tv/globosatplay/tracks";
            //     folder.items.push(request);
            //     console.log("i");
            // }

            folder.items.map(request => {
                console.log("map");
                request.id = guid();
                return request;
            })
            return folder;
        })

        return storage;
    }

    createStorageFolder(callback) {
        mkdirp(this.storageFilePath, (err) => {
            console.log("createStorageFolder: ", "An error ocurred creating the file " + err);
            return callback();
        });
    }

    createStorageFile(callback) {
        this.createStorageFolder(() => {
            fs.writeFile(this.storageFileURL, JSON.stringify(this.initialStorage), (err) => {
                if (err) {
                    console.log("createStorageFile: ", "An error ocurred creating the file " + err);<commit_msg>refactor<commit_after>import {initialStorage} from "./../data/initialStorage";
import guid from "./guid";

const fs = window.require("fs");
const mkdirp = window.require("mkdirp");
const dialog = window.require('electron').remote.dialog;

export default class File {

    constructor() {
        this.storageFileName = "requesto.json";
        this.storageFilePath = `/Users/${window.process.env.USER}/.requesto/`;
        this.storageFileURL = `${this.storageFilePath}${this.storageFileName}`
        this.initialStorage = initialStorage;
        this.checkStorageHealth = this.checkStorageHealth.bind(this);
        this.createStorageFolder = this.createStorageFolder.bind(this);
        this.createStorageFile = this.createStorageFile.bind(this);
        this.loadStorageFile = this.loadStorageFile.bind(this);
        this.exportStorage = this.exportStorage.bind(this);

    }

    checkStorageHealth(data){
        var storage = JSON.parse(data);
        storage.folders.map(folder => {
            folder.id = guid();

            folder.items.map(request => {
                console.log("map");
                request.id = guid();
                return request;
            })
            return folder;
        })

        return storage;
    }

    createStorageFolder(callback) {
        mkdirp(this.storageFilePath, (err) => {
            console.log("createStorageFolder: ", "An error ocurred creating the file " + err);
            return callback();
        });
    }

    createStorageFile(callback) {
        this.createStorageFolder(() => {
            fs.writeFile(this.storageFileURL, JSON.stringify(this.initialStorage), (err) => {
                if (err) {
                    console.log("createStorageFile: ", "An error ocurred creating the file " + err);
{'fraction_non_alphanumeric': 0.1339894019682059, 'fraction_numerical': 0.001514004542013626, 'mean_word_length': 2.189058728881738, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '1760273', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1047, 'n_words': 188}