<commit_before>// app state shared with login.html:
// =================================
// localStorage::"unhosted".userAddress
// localStorage::"unhosted".davAuth
// localStorage::"unhosted".cryptoPwd
// localStorage::"unhosted".davBaseUrl


  /////////
 // DAV //
/////////

var DAV = function() {
	var dav = {}
	keyToUrl = function(key, wallet) {
		var userAddressParts = wallet.userAddress.split("@");
		var resource = document.domain;
		var url = wallet.davBaseUrl
			+"webdav/"+userAddressParts[1]
			+"/"+userAddressParts[0]
			+"/"+resource
			+"/"+key;
		return url;
	}
	dav.get = function(key) {
		var wallet = getWallet();
		var xhr = new XMLHttpRequest();
		xhr.open("GET", keyToUrl(key, wallet), false);
		xhr.send();
		if(xhr.status == 200) {
			return xhr.responseText;
		} if(xhr.status == 404) {
			return null;
		} else {
			alert("error: got status "+xhr.status+" when doing basic auth GET on url "+keyToUrl(key));
		}
	}
	dav.put = function(key, text) {
		var wallet = getWallet();
		var xhr = new XMLHttpRequest();
		xhr.open("PUT", keyToUrl(key, wallet), false);
		xhr.setRequestHeader("Authorization", wallet.davAuth);
		xhr.withCredentials = "true";
		xhr.send(text);
		if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
			alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+keyToUrl(key));
		}
	}
	return dav;
}


  //////////////
 // Unhosted //
//////////////

var Unhosted = function() {
	var unhosted = {};
	var dav = DAV();
	unhosted.connect = function() {
		if(!getWallet().davAuth) {
			window.location = config.loginUrl;
		}
	}
	unhosted.getUserName = function() {
		return getWallet().userAddress;
	}
	unhosted.get = function(key) {
		return JSON.parse(dav.get(key));
		//return JSON.parse(sjcl.decrypt(localStorage.getItem("unhosted").cryptoPwd, dav.get(key)));
	}
	unhosted.set = function(key, value) {
		dav.put(key, JSON.stringify(value));
		//dav.put(key, sjcl.encrypt(localStorage.getItem("unhosted").cryptoPwd, JSON.stringify(value)));
	}
	unhosted.close = function() {
		setWallet({});
		window.location = config.loginUrl;
	}

	return unhosted;
}<commit_msg>turned crypto back on<commit_after>// app state shared with login.html:
// =================================
// localStorage::"unhosted".userAddress
// localStorage::"unhosted".davAuth
// localStorage::"unhosted".cryptoPwd
// localStorage::"unhosted".davBaseUrl


  /////////
 // DAV //
/////////

var DAV = function() {
	var dav = {}
	keyToUrl = function(key, wallet) {
		var userAddressParts = wallet.userAddress.split("@");
		var resource = document.domain;
		var url = wallet.davBaseUrl
			+"webdav/"+userAddressParts[1]
			+"/"+userAddressParts[0]
			+"/"+resource
			+"/"+key;
		return url;
	}
	dav.get = function(key) {
		var wallet = getWallet();
		var xhr = new XMLHttpRequest();
		xhr.open("GET", keyToUrl(key, wallet), false);
		xhr.send();
		if(xhr.status == 200) {
			return xhr.responseText;
		} if(xhr.status == 404) {
			return null;
		} else {
			alert("error: got status "+xhr.status+" when doing basic auth GET on url "+keyToUrl(key));
		}
	}
	dav.put = function(key, text) {
		var wallet = getWallet();
		var xhr = new XMLHttpRequest();
		xhr.open("PUT", keyToUrl(key, wallet), false);
		xhr.setRequestHeader("Authorization", wallet.davAuth);
		xhr.withCredentials = "true";
		xhr.send(text);
		if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
			alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+keyToUrl(key));
		}
	}
	return dav;
}


  //////////////
 // Unhosted //
//////////////

var Unhosted = function() {
	var unhosted = {};
	var dav = DAV();
	unhosted.connect = function() {
		if(!getWallet().davAuth) {
			window.location = config.loginUrl;
		}
	}
	unhosted.getUserName = function() {
		return getWallet().userAddress;
	}
	unhosted.get = function(key) {
		var wallet = getWallet();
		if(wallet.cryptoPwd == null) {
			return JSON.parse(dav.get(key));
		} else {
			return JSON.parse(sjcl.decrypt(wallet.cryptoPwd, dav.get(key)));
		}
	}
	unhosted.set = function(key, value) {
		var wallet = getWallet();
		if(wallet.cryptoPwd == null) {
			dav.put(key, JSON.stringify(value));
		} else {
			dav.put(key, sjcl.encrypt(wallet.cryptoPwd, JSON.stringify(value)));
		}
	}
	unhosted.close = function() {
		setWallet({});
		window.location = config.loginUrl;
	}

	return unhosted;
}
{'fraction_non_alphanumeric': 0.20282588878760255, 'fraction_numerical': 0.007748404740200547, 'mean_word_length': 3.4877300613496933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2817499', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1560, 'n_words': 311}