<commit_before>var app = angular.module('valetState', ['ngResource', 'ngAnimate', 'ngRoute']);
// stateCtrl
app.controller('loginCtrl', function ($scope, $window, $http, $sce) {

	// Get user's spotify information/profile
	console.log('location host is', location.host);
	var user = {};
	$http.get('http://' + location.host + '/spotify/isAuthenticated').then(function (response) {
		console.log('user info response is', response);
		if (response.data.auth) {
			var userProps = Object.keys(response.data.userInfo);
			for (var i = 0; i < userProps.length; i++) {
				var property = userProps[i];
				var val = response.data.userInfo[property];
				Object.defineProperty(user, property, {
					value: val,
					enumerable: true,
					configurable: true
				});
			}
			$scope.userInfo = user;
			console.log('scope', $scope.userInfo);
		} else {
			alert('Login token has expired. Please log in again.');
			$window.location.href = '/';
		}
	});

	//Get user's spotify playlists
	$http.get('http://' + location.host + '/spotify/getPlaylists').then(function (response) {
		console.log(response);
		if (response.error) {
			alert('Could not authorize request for user playlists. Please sign in later.');
			$window.location.href = '/';
		} else {
			console.log('playlist response items are', response.data.data.items);
			$scope.playlists = response.data.data.items;
		}
	});

	$scope.userName = function () {
		if (user.display_name == null) {
			return user.id;
		} else {
			return user.display_name;
		}
	};

	//Get songs for a playlist
	$scope.getSongs = function (plistID) {
		console.log('getSongs triggered. playlistID:', plistID, 'userID:', user.id);
		$http.get('http://' + location.host + '/spotify/getSongs', {
			params: {
				userID: user.id,
				playlistID: plistID
			}
		}).then(function (response) {
			console.log('getSongs response', response);
			console.log('response error:', response.error);
			if (response.data.error) {
				alert('Spotify encountered an error receiving tracks for this playlist.');
			} else {
				$scope.tracks = response.data.data.items;
				playlistSelected();
			}
		}, function errorCallback(response) {
			console.log('Server error', response.data.error.status, response.data.error.statusText);
		});
	};

	/*
	* STATE MANAGEMENT
	*/
	// Handle state changes within the application
	function playlistSelected() {
		console.log('selecting playlist...');
		$scope.playlistSelected = true;
	}
	function playlistDeselected() {
		console.log('deselecting playlist...');
		$scope.playlistSelected = false;
	}
	function youtubeQueried() {
		console.log('youtube has been sent a request...');
		$scope.youtubeSearched = true;
	}
	$scope.playlistSelected = false;
	$scope.selectPlaylist = playlistSelected;
	$scope.deselectPlaylist = playlistDeselected;
	$scope.youtubeSearched = false;
	$scope.searchYoutube = youtubeQueried;

	/*
     * YOUTUBE REQUESTS
	 */

	// Handle youtube search requests
	function searchRequest(query) {
		return new Promise(function (resolve, reject) {

			// Return an embed link of a youtube video
			$http.get('http://' + location.host + '/youtube/search', {
				params: {
					searchQuery: query
				}
			}).then(function (response) {
				if (response.data.error) {
					alert('some youtube error has occurred');
					console.log('error response for youtube is', response);
					reject(response.data.error);
				} else {
					resolve(JSON.parse(response.data.body));
				}
			});
		});
	}

	function findVideos(tracks) {
		var videoLinks = [];
		for (var i = 0; i < tracks.length; i++) {
			var track = tracks[i];
			var query = track.track.artists[0].name + track.track.name;
			searchRequest(query).then(function (response) {
				videoLinks.push(
					{
						link: $sce.trustAsResourceUrl("https://www.youtube.com/embed/" + response.items[0].id.videoId)
					});
			}, function (error) {
				console.log(error);
			});
		}
		$scope.links = videoLinks;
		if ($scope.links) {
			$scope.youtubeSearched = true;
		}
		console.log('$scope.links contains', $scope.links);
	}
	$scope.findVideos = findVideos;
});

app.controller('titleCtrl', function ($scope, $http, $window) {
	$http.get('http://' + location.host + '/spotify/isAuthenticated').then(function (response) {
		$scope.auth = response.data.auth;
	});

	$scope.whichRoot = function () {
		console.log('whichRoot has been triggered');<commit_msg>Convert double quotes to single quotes<commit_after>var app = angular.module('valetState', ['ngResource', 'ngAnimate', 'ngRoute']);
// stateCtrl
app.controller('loginCtrl', function ($scope, $window, $http, $sce) {

	// Get user's spotify information/profile
	console.log('location host is', location.host);
	var user = {};
	$http.get('http://' + location.host + '/spotify/isAuthenticated').then(function (response) {
		console.log('user info response is', response);
		if (response.data.auth) {
			var userProps = Object.keys(response.data.userInfo);
			for (var i = 0; i < userProps.length; i++) {
				var property = userProps[i];
				var val = response.data.userInfo[property];
				Object.defineProperty(user, property, {
					value: val,
					enumerable: true,
					configurable: true
				});
			}
			$scope.userInfo = user;
			console.log('scope', $scope.userInfo);
		} else {
			alert('Login token has expired. Please log in again.');
			$window.location.href = '/';
		}
	});

	//Get user's spotify playlists
	$http.get('http://' + location.host + '/spotify/getPlaylists').then(function (response) {
		console.log(response);
		if (response.error) {
			alert('Could not authorize request for user playlists. Please sign in later.');
			$window.location.href = '/';
		} else {
			console.log('playlist response items are', response.data.data.items);
			$scope.playlists = response.data.data.items;
		}
	});

	$scope.userName = function () {
		if (user.display_name == null) {
			return user.id;
		} else {
			return user.display_name;
		}
	};

	//Get songs for a playlist
	$scope.getSongs = function (plistID) {
		console.log('getSongs triggered. playlistID:', plistID, 'userID:', user.id);
		$http.get('http://' + location.host + '/spotify/getSongs', {
			params: {
				userID: user.id,
				playlistID: plistID
			}
		}).then(function (response) {
			console.log('getSongs response', response);
			console.log('response error:', response.error);
			if (response.data.error) {
				alert('Spotify encountered an error receiving tracks for this playlist.');
			} else {
				$scope.tracks = response.data.data.items;
				playlistSelected();
			}
		}, function errorCallback(response) {
			console.log('Server error', response.data.error.status, response.data.error.statusText);
		});
	};

	/*
	* STATE MANAGEMENT
	*/
	// Handle state changes within the application
	function playlistSelected() {
		console.log('selecting playlist...');
		$scope.playlistSelected = true;
	}
	function playlistDeselected() {
		console.log('deselecting playlist...');
		$scope.playlistSelected = false;
	}
	function youtubeQueried() {
		console.log('youtube has been sent a request...');
		$scope.youtubeSearched = true;
	}
	$scope.playlistSelected = false;
	$scope.selectPlaylist = playlistSelected;
	$scope.deselectPlaylist = playlistDeselected;
	$scope.youtubeSearched = false;
	$scope.searchYoutube = youtubeQueried;

	/*
     * YOUTUBE REQUESTS
	 */

	// Handle youtube search requests
	function searchRequest(query) {
		return new Promise(function (resolve, reject) {

			// Return an embed link of a youtube video
			$http.get('http://' + location.host + '/youtube/search', {
				params: {
					searchQuery: query
				}
			}).then(function (response) {
				if (response.data.error) {
					alert('some youtube error has occurred');
					console.log('error response for youtube is', response);
					reject(response.data.error);
				} else {
					resolve(JSON.parse(response.data.body));
				}
			});
		});
	}

	function findVideos(tracks) {
		var videoLinks = [];
		for (var i = 0; i < tracks.length; i++) {
			var track = tracks[i];
			var query = track.track.artists[0].name + track.track.name;
			searchRequest(query).then(function (response) {
				videoLinks.push(
					{
						link: $sce.trustAsResourceUrl('https://www.youtube.com/embed/' + response.items[0].id.videoId)
					});
			}, function (error) {
				console.log(error);
			});
		}
		$scope.links = videoLinks;
		if ($scope.links) {
			$scope.youtubeSearched = true;
		}
		console.log('$scope.links contains', $scope.links);
	}
	$scope.findVideos = findVideos;
});

app.controller('titleCtrl', function ($scope, $http, $window) {
	$http.get('http://' + location.host + '/spotify/isAuthenticated').then(function (response) {
		$scope.auth = response.data.auth;
	});

	$scope.whichRoot = function () {
		console.log('whichRoot has been triggered');
{'fraction_non_alphanumeric': 0.1594616174289951, 'fraction_numerical': 0.000912512832211703, 'mean_word_length': 3.6050420168067228, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3162856', 'n_tokens_mistral': 3278, 'n_tokens_neox': 2817, 'n_words': 612}