<commit_before>var fileManager = function (dataService) {
	var callBack;
	var uplType;
	var postId;

	function uploadClick(uploadType, id) {
		uplType = uploadType;

		if (uploadType === 'AppLogo') { callBack = appLogoCallback; }
		if (uploadType === 'AppCover') { callBack = appCoverCallback; }
		if (uploadType === 'PostImage') { callBack = insertImgCallback; }
		if (uploadType === 'PostCover') { callBack = postCoverCallback; postId = id; }
		if (uploadType === 'Avatar') { callBack = userAvatarCallback; }

		$('#file').trigger('click');
		return false;
	}

	function uploadSubmit() {
		var data = new FormData($('#frmUpload')[0]);
		var url = postId > 0 ? 'api/storage/upload/' + uplType + '?postId=' + postId : 'api/storage/upload/' + uplType;
		dataService.upload(url, data, callBack, fail);
	}

	function appLogoCallback(data) {
		$('#logo').val(data);
	}

	function appCoverCallback(data) {
		$('#cover').val(data);
	}

   function postCoverCallback(data) {
     var cover = document.getElementById("post-cover");
     cover.src = data;

     $('#post-cover-txt').val(data);
	}

  function userAvatarCallback(data) {
    $('#avatar').attr("src", data);
    $("#avatar-menu").attr("src", data);
    $("#avatar-submenu").attr("src", data);
  }

	function insertImgCallback(data) {
		var cm = _editor.codemirror;
		var url = data;
		var output = url + '](' + url + ')';

		if (url.toLowerCase().match(/.(mp4|ogv|webm)$/i)) {
			var extv = 'mp4';
			if (url.toLowerCase().match(/.(ogv)$/i)) { extv = 'ogg'; }
			if (url.toLowerCase().match(/.(webm)$/i)) { extv = 'webm'; }
			output = '<video width="320" height="240" controls>\r\n  <source src="' + url;
			output += '" type="video/' + extv + '">Your browser does not support the video tag.\r\n</video>';
		}
		else if (url.toLowerCase().match(/.(mp3|ogg|wav)$/i)) {
			var exta = 'mp3';
			if (url.toLowerCase().match(/.(ogg)$/i)) { exta = 'ogg'; }
			if (url.toLowerCase().match(/.(wav)$/i)) { exta = 'wav'; }
			output = '<audio controls>\r\n  <source src="' + url;
			output += '" type="audio/' + exta + '">Your browser does not support the audio tag.\r\n</audio>';
		}
		else if (url.toLowerCase().match(/.(jpg|jpeg|png|gif)$/i)) {
			output = '\r\n![' + output;
		}
		else {
			output = '\r\n[' + output;
		}
		var selectedText = cm.getSelection();
		cm.replaceSelection(output);
	}

	function fail(data) {
		console.log(data.url);
	}

	return {
		uploadClick: uploadClick,
		uploadSubmit: uploadSubmit
	};
}(DataService);

$('.bf-posts-list .item-link-desktop').click(function () {
	$('.bf-posts-list .item-link-desktop').removeClass('active');
	$(this).addClass('active');
});
<commit_msg>#275 File Manager part 1<commit_after>let fileManager = function (dataService) {
  let inputFile = document.getElementById('frmUploadFile');
  let frmUpload = document.getElementById('frmUpload');
  let callBack;
  let uplType;
  let postId;

  function uploadClick(uploadType, id) {
    uplType = uploadType;

    if (uploadType === 'AppCover') { callBack = appCoverCallback; }
    if (uploadType === 'PostImage') { callBack = insertImgCallback; }
    if (uploadType === 'PostCover') { callBack = postCoverCallback; postId = id; }
    if (uploadType === 'Avatar') { callBack = userAvatarCallback; }

    inputFile.click();
    return false;
  }

  function uploadSubmit() {
    let data = new FormData(frmUpload);
    let url = postId > 0 ? `api/storage/upload/${uplType}?postId=${postId}` : `api/storage/upload/${uplType}`;
    dataService.upload(url, data, callBack, fail);
  }

  function appCoverCallback(data) {
    let defaultCover = document.getElementById('defaultCover');
    defaultCover.value = data;
  }

  function postCoverCallback(data) {
    var postCover = document.getElementById("postCover");
    postCover.src = data;
  }

  function userAvatarCallback(data) {
    $('#avatar').attr("src", data);
    $("#avatar-menu").attr("src", data);
    $("#avatar-submenu").attr("src", data);
  }

  function insertImgCallback(data) {
    var cm = _editor.codemirror;
    var url = data;
    var output = url + '](' + url + ')';

    if (url.toLowerCase().match(/.(mp4|ogv|webm)$/i)) {
      var extv = 'mp4';
      if (url.toLowerCase().match(/.(ogv)$/i)) { extv = 'ogg'; }
      if (url.toLowerCase().match(/.(webm)$/i)) { extv = 'webm'; }
      output = '<video width="320" height="240" controls>\r\n  <source src="' + url;
      output += '" type="video/' + extv + '">Your browser does not support the video tag.\r\n</video>';
    }
    else if (url.toLowerCase().match(/.(mp3|ogg|wav)$/i)) {
      var exta = 'mp3';
      if (url.toLowerCase().match(/.(ogg)$/i)) { exta = 'ogg'; }
      if (url.toLowerCase().match(/.(wav)$/i)) { exta = 'wav'; }
      output = '<audio controls>\r\n  <source src="' + url;
      output += '" type="audio/' + exta + '">Your browser does not support the audio tag.\r\n</audio>';
    }
    else if (url.toLowerCase().match(/.(jpg|jpeg|png|gif)$/i)) {
      output = '\r\n![' + output;
    }
    else {
      output = '\r\n[' + output;
    }
    var selectedText = cm.getSelection();
    cm.replaceSelection(output);
  }

  function fail(data) {
    console.log(data.url);
  }

  return {
    uploadClick: uploadClick,
    uploadSubmit: uploadSubmit
  };
}(DataService);

{'fraction_non_alphanumeric': 0.1975706965268552, 'fraction_numerical': 0.005124312013664832, 'mean_word_length': 3.511986301369863, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266125', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1833, 'n_words': 376}