<commit_before>'use strict';

const moodbored = 'moodbored';

// requires
const { remote } = require('electron');
const { Menu, MenuItem } = remote;
const { dialog } = remote;
const fs = require('fs');
const request = require('request');
const trash = require('trash');
const shell = require('electron').shell;

const _options = require('./js/renderer/options.js');

// directory variables
let rootDirectory = '';
let currentPath = rootDirectory;

// temporary element storage
let imageElements = [];
let imageSrcs = [];
let imgFileTypes = /.(jpg|png|gif|jpeg|bmp|webp|svg)/;

// container elements
let body = document.getElementsByTagName('body')[0];
let mainContainer = document.getElementById('main');
let sidebar = document.getElementById('sidebar');
let view = document.getElementById('view');
let folderView = document.getElementById('folders');
let imageView = document.getElementById('images');

let lastFolderButton = null;

// option/input elements
let openFolderCtrl = document.getElementById('open-folder-ctrl');

// ~~~~~~~~~ drag and drop ~~~~~~~~~

var dropzone = function () {
  var elem = document.getElementById('image-drop');

  function init() {
    elem.addEventListener('dragover', copy, false)
    imageView.addEventListener('dragover', copy, false)

    imageView.addEventListener('dragenter', (e) => {
      e.stopPropagation();
      e.preventDefault();
      if (elem.classList.contains('hidden')) {
        elem.innerText = "drop here to add image to folder";
        elem.classList.remove('hidden');
      }
    }, false)

    elem.addEventListener('dragleave', (e) => {
      e.stopPropagation();
      e.preventDefault();
      if (!elem.classList.contains('hidden')) {
        elem.classList.add('hidden');
      }
    }, false)

    imageView.addEventListener('drop', dropEv, false)
    elem.addEventListener('drop', dropEv, false)

    function dropEv(e) {
      e.stopPropagation();
      e.preventDefault();
      drop(e);
    }
  }
  init();

  function copy (e) {
    e.dataTransfer.dropEffect = (options.moveFile) ? 'move' : 'copy';
    e.preventDefault();
    e.stopPropagation();
  }

  function drop (e, altPath) {
    let localFile = (e.dataTransfer.files.length > 0);
    let files = (localFile) ? e.dataTransfer.files : [e.dataTransfer.getData('text/html')];
    // if localFile is true, it's a file, false it's data
    for (let file of files) {
      upload(file, altPath, localFile);
    }
  }

  function upload(data, altPath, localFile) {
    // set local data var
    let _data = data;

    let _currentPath = altPath || currentPath;
    let path = _currentPath + '/';
    let name = '';

    if (!localFile) {
      let imgSrc = /http[^"\n\r]*(?=")/i;
      _data = _data.substring(_data.indexOf('src="') + 5).match(imgSrc)[0];
    }

    let isImage = (localFile) ? _data.type.match(imgFileTypes) : _data.match(imgFileTypes);

    if (!isImage) {
      notification(false, name, 'not an image');
      return;
    }

    let date = new Date().toISOString().replace(/:/gi, '.');
    name = (localFile) ? _data.name : date + isImage[0];
    path += name;

    if (fs.existsSync(path)) {
      notification(false, name, 'file already exists');
      return;
    }

    let r = (localFile) ? fs.createReadStream(_data.path) : request(_data);
    if (localFile) {
      r.on('open', () => {
        writeImage();
      })
    } else {
      writeImage();
    }

    function writeImage() {
      r.pipe(fs.createWriteStream(path));
      r.on('end', function() {
        console.log('image done loading, creating image');
        CreateImage(currentPath, name, true);
      });
    }

    if (localFile && options.moveFile) {
      fs.unlinkSync(_data.path);
    }

    notification(true, name);
  }

  function notification (success, name, reason, time) {
    let _time = time || 1250;
    let _reason = reason || '';
    let text = '';
    let result = (success) ? ' successfully added!' : ' not added, ';
    text = name + result + _reason;
    dropzone.elem.innerText = text;
    setTimeout(() => {
      dropzone.elem.classList.add('hidden');
    }, _time);
  }

  return {
    elem: elem,
    copy: copy,
    drop: drop
  }
}();
<commit_msg>folders can now be dragged into the window to be added<commit_after>'use strict';

const moodbored = 'moodbored';

// requires
const { remote } = require('electron');
const { Menu, MenuItem } = remote;
const { dialog } = remote;
const fs = require('fs');
const request = require('request');
const trash = require('trash');
const shell = require('electron').shell;

const _options = require('./js/renderer/options.js');

// directory variables
let rootDirectory = '';
let currentPath = rootDirectory;

// temporary element storage
let imageElements = [];
let imageSrcs = [];
let imgFileTypes = /.(jpg|png|gif|jpeg|bmp|webp|svg)/;

// container elements
let body = document.getElementsByTagName('body')[0];
let mainContainer = document.getElementById('main');
let sidebar = document.getElementById('sidebar');
let view = document.getElementById('view');
let folderView = document.getElementById('folders');
let imageView = document.getElementById('images');

let lastFolderButton = null;

// option/input elements
let openFolderCtrl = document.getElementById('open-folder-ctrl');

// ~~~~~~~~~ drag and drop ~~~~~~~~~

var dropzone = function () {
  var elem = document.getElementById('image-drop');

  function init() {
    elem.addEventListener('dragover', copy, false)
    imageView.addEventListener('dragover', copy, false)

    imageView.addEventListener('dragenter', (e) => {
      e.stopPropagation();
      e.preventDefault();
      if (elem.classList.contains('hidden')) {
        elem.innerText = "drop here to add image to folder";
        elem.classList.remove('hidden');
      }
    }, false)

    elem.addEventListener('dragleave', (e) => {
      e.stopPropagation();
      e.preventDefault();
      if (!elem.classList.contains('hidden')) {
        elem.classList.add('hidden');
      }
    }, false)

    imageView.addEventListener('drop', dropEv, false)
    elem.addEventListener('drop', dropEv, false)

    function dropEv(e) {
      e.stopPropagation();
      e.preventDefault();
      drop(e);
    }
  }
  init();

  function copy (e) {
    e.dataTransfer.dropEffect = (options.moveFile) ? 'move' : 'copy';
    e.preventDefault();
    e.stopPropagation();
  }

  function drop (e, altPath) {
    let localFile = (e.dataTransfer.files.length > 0);
    let files = (localFile) ? e.dataTransfer.files : [e.dataTransfer.getData('text/html')];
    // if localFile is true, it's a file, false it's data
    for (let file of files) {
      upload(file, altPath, localFile);
    }
  }

  function upload(data, altPath, localFile) {
    let isFolder = !data.type
    if (isFolder) {
      console.log('is a folder!')
      console.log(data.path)
      let _root = data.path;
      console.log(_root)
      GetNewDirectoryStructure(_root);
      LoadDirectoryContents(_root, true);
      CreateFolderView();

      notification({ custom: 'new folder successfully added!' });
      return;
    }
    // set local data var
    let _data = data;

    let _currentPath = altPath || currentPath;
    let path = _currentPath + '/';
    let name = '';
    let domain = '';

    if (!localFile) {
      let imgSrc = /http[^"\n\r]*(?=")/i;
      _data = _data.substring(_data.indexOf('src="') + 5).match(imgSrc)[0];
      domain = _data.substring(0, _data.indexOf('/') + 1)
      // console.log('domain: ' + domain)
    }

    let isImage = (localFile) ? _data.type.match(imgFileTypes) : _data.match(imgFileTypes);

    if (!isImage) {
      notification({ success: false, name: name, reason: 'not an image' });
      return;
    }

    let date = new Date().toISOString().replace(/:/gi, '.');
    name = (localFile) ? _data.name : date + isImage[0];
    path += name;

    if (fs.existsSync(path)) {
      notification({ success: false, name: name, reason: 'file already exists' });
      return;
    }

    let r = (localFile) ? fs.createReadStream(_data.path) : request(_data);
    if (localFile) {
      r.on('open', () => {
        writeImage();
      })
    } else {
      writeImage();
    }

    function writeImage() {
      r.pipe(fs.createWriteStream(path));
      r.on('end', function() {
        console.log('image done loading, creating image');
        CreateImage(currentPath, name, true);
      });
    }

    if (localFile && options.moveFile) {
      fs.unlinkSync(_data.path);
    }

    notification({ success: true, name: name });
  }


  // arg object structure
  // success, name, reason, time
  // {
  //   success: bool,
  //   name: string,
  //   reason: string,
  //   time: int
  // }
  function notification (args) {
    let _time = args.time || 1250;
    if (args.custom) {
      dropzone.elem.innerText = args.custom
      setTimeout(() => {
        dropzone.elem.classList.add('hidden');
      }, _time);
      return;
    }
    let _name = args.name || 'this file';
    let _reason = args.reason || '';
    let text = '';
    let result = (args.success) ? ' successfully added!' : ' not added, ';
    text = _name + result + _reason;
    dropzone.elem.innerText = text;
    setTimeout(() => {
      dropzone.elem.classList.add('hidden');
    }, _time);
  }

  return {
    elem: elem,
    copy: copy,
    drop: drop
  }
}();

{'fraction_non_alphanumeric': 0.16089373530040624, 'fraction_numerical': 0.0021381227282446015, 'mean_word_length': 2.9893390191897655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '558981', 'n_tokens_mistral': 2890, 'n_tokens_neox': 2860, 'n_words': 672}