<commit_before>var lang = 'en-US'
var accessToken = '<KEY>'
var space_id = 'vxu5be6w735m'
var query = {}
query.content_type = 'ashTree'
var baseAPI = 'https://api.contentful.com'
var assetAPI = baseAPI +"/spaces/" + space_id + "/assets/<asset_id>"; // ?access_token=" + accessToken;

var client = contentful.createClient({
  // This is the access token for this space. Normally you get the token in the Contentful web app
  accessToken: accessToken
})


function assetEndpoint(asset_id) {
  return assetAPI.replace("<asset_id>", asset_id);
}

function getPreciseLocation() {
  return new Promise(function (resolve, reject) {
    navigator.geolocation.getCurrentPosition(function (position) {
      resolve([position.coords.latitude, position.coords.longitude]);
    });
  });
}

function createAshTreeImages(entry) {
  client.getSpace(space_id)
  .then((space) => space.createEntry('ashTreeImages', {
    fields: {
      s3url: {
        'en-US': 'https://s3.amazonaws.com/ash-tree-photos/' + img_name
      },
      imageType: {
        'en-US': 'Tree'
      },
      ashTree: {
        'en-US': {
          sys: {
            type: 'Link',
            linkType: 'Entry',
            id: entry.sys.id
          }
        }
      }
    }
  }))
  .then((entry) => console.log(entry))
  .catch(console.error)
}

function done(entry){
  window.location.replace('./uploadsuccess.html')
}

function createAshTree(data) {
  var d = new Date();
  var n = d.toISOString();
  client.getSpace(space_id)
  .then((space) => space.createEntry('ashTree', {
    fields: {
      latlong: {
        'en-US': {
          lat: data[0],
          lon: data[1]
        }
      },
      datetime: {
        'en-US': n
      },
      s3url: {
        'en-US': 'https://s3.amazonaws.com/ash-tree-photos/' + img_name
      }
    }
  }))
  .then((entry) => done(entry))//refresh())
  .catch(console.error)
}

var input = document.querySelector("input[type=file]");
var result_image_obj = '';
var img_name;

input.addEventListener("change", function (e) {
  img_name = input.files[0].name;
  console.log(input.files[0]);
  alert(input.files[0].size);
  var label = $(e.target).prev();
  label.css("border", "green solid 2px");
  createImageBitmap(input.files[0])
    .then(response => {
      compress(response);
    });
});

function compress(source_img_obj) {
	var cvs = document.createElement("canvas");
    cvs.width = source_img_obj.width;
    cvs.height = source_img_obj.height;
    var ctx = cvs.getContext("2d").drawImage(source_img_obj, 0, 0);
    var newImageData = cvs.toDataURL("image/jpeg", 0.5);
    result_image_obj = newImageData;
}

//Add Photo
$(document).on("click", "#upload", function(){
  // Update entry
<commit_msg>added file type type alert<commit_after>var lang = 'en-US'
var accessToken = '<KEY>'
var space_id = 'vxu5be6w735m'
var query = {}
query.content_type = 'ashTree'
var baseAPI = 'https://api.contentful.com'
var assetAPI = baseAPI +"/spaces/" + space_id + "/assets/<asset_id>"; // ?access_token=" + accessToken;

var client = contentful.createClient({
  // This is the access token for this space. Normally you get the token in the Contentful web app
  accessToken: accessToken
})


function assetEndpoint(asset_id) {
  return assetAPI.replace("<asset_id>", asset_id);
}

function getPreciseLocation() {
  return new Promise(function (resolve, reject) {
    navigator.geolocation.getCurrentPosition(function (position) {
      resolve([position.coords.latitude, position.coords.longitude]);
    });
  });
}

function createAshTreeImages(entry) {
  client.getSpace(space_id)
  .then((space) => space.createEntry('ashTreeImages', {
    fields: {
      s3url: {
        'en-US': 'https://s3.amazonaws.com/ash-tree-photos/' + img_name
      },
      imageType: {
        'en-US': 'Tree'
      },
      ashTree: {
        'en-US': {
          sys: {
            type: 'Link',
            linkType: 'Entry',
            id: entry.sys.id
          }
        }
      }
    }
  }))
  .then((entry) => console.log(entry))
  .catch(console.error)
}

function done(entry){
  window.location.replace('./uploadsuccess.html')
}

function createAshTree(data) {
  var d = new Date();
  var n = d.toISOString();
  client.getSpace(space_id)
  .then((space) => space.createEntry('ashTree', {
    fields: {
      latlong: {
        'en-US': {
          lat: data[0],
          lon: data[1]
        }
      },
      datetime: {
        'en-US': n
      },
      s3url: {
        'en-US': 'https://s3.amazonaws.com/ash-tree-photos/' + img_name
      }
    }
  }))
  .then((entry) => done(entry))//refresh())
  .catch(console.error)
}

var input = document.querySelector("input[type=file]");
var result_image_obj = '';
var img_name;

input.addEventListener("change", function (e) {
  img_name = input.files[0].name;
  var tempFile = input.files[0];
  alert(tempFile.name, tempFile.size, tempFile.type);
  var label = $(e.target).prev();
  label.css("border", "green solid 2px");
  createImageBitmap(input.files[0])
    .then(response => {
      compress(response);
    });
});

function compress(source_img_obj) {
	var cvs = document.createElement("canvas");
    cvs.width = source_img_obj.width;
    cvs.height = source_img_obj.height;
    var ctx = cvs.getContext("2d").drawImage(source_img_obj, 0, 0);
    var newImageData = cvs.toDataURL("image/jpeg", 0.5);
    result_image_obj = newImageData;
}

//Add Photo
$(document).on("click", "#upload", function(){
  // Update entry

{'fraction_non_alphanumeric': 0.1641954969796815, 'fraction_numerical': 0.007505033864177192, 'mean_word_length': 2.9536903039073805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 6, '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': '1834605', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1845, 'n_words': 350}