Moved SoundCloud api-key out to different config file and fixed some list-naming issues that was caused with filter.clean was performed after list-name was encoded. Closes #362

This commit is contained in:
Kasper Rynning-Tønnesen
2018-08-01 16:53:26 +02:00
parent a190e66c23
commit 65698b02a0
20 changed files with 139 additions and 100 deletions

View File

@@ -86,11 +86,11 @@ app.use(function (req, res, next) {
} else {
if (cookie === undefined) {
try {
console.error((new Date), "originalUrl", req.originalUrl);
console.error((new Date), "couldn't fetch cookie for some reason, maybe no cookie exists?", req.get('origin'), "couldn't fetch cookie for some reason, maybe no cookie exists?");
//console.error((new Date), "originalUrl", req.originalUrl);
//console.error((new Date), "couldn't fetch cookie for some reason, maybe no cookie exists?", req.get('origin'), "couldn't fetch cookie for some reason, maybe no cookie exists?");
} catch(e) {
console.error((new Date), "couldn't fetch origin");
//console.error((new Date), "couldn't fetch origin");
}
var user_name = Functions.hash_pass(Functions.rndName(uniqid.time(), 15));
res.cookie('_uI', user_name, {

View File

@@ -1,4 +1,7 @@
var api_key = "xxxx";
var api_key = {
"youtube": "xxxx",
"soundcloud": "",
};
try {
module.exports = api_key;

View File

@@ -79,7 +79,7 @@ function chat(msg, guid, offline, socket) {
}
var coll = msg.channel.toLowerCase();//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
@@ -132,7 +132,7 @@ function all_chat(msg, guid, offline, socket) {
var coll = msg.channel.toLowerCase();//.replace(/ /g,'');
var data = msg.data;
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
Functions.check_inlist(coll, guid, socket, offline);
if(data !== "" && data !== undefined && data !== null &&
data.length < 151 && data.replace(/\s/g, '').length){

View File

@@ -11,9 +11,12 @@ var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials
var crypto = require('crypto');
var db = require(pathThumbnails + '/handlers/db.js');
var uniqid = require('uniqid');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
function encodeChannelName(str) {
var _fn = encodeURIComponent;
str = filter.clean(str);
var toReturn = _fn(str);
toReturn = toReturn.replace(/_/g, "%5F");
toReturn = toReturn.replace(/%26amp%3B/g, "%26").replace(/%26amp%3b/g, "%26");
@@ -25,6 +28,7 @@ function decodeChannelName(str) {
var _fn = decodeURIComponent;
str = str.toUpperCase();
var toReturn = _fn(str.replace(/%5F/g, "_"));
toReturn = filter.clean(toReturn);
return toReturn.toLowerCase();
}

View File

@@ -99,9 +99,12 @@ module.exports = function() {
typeof(msg.channel) == "string" && typeof(msg.socket_id) == "string" && msg.channel != "") {
db.collection("connected_users").find({"_id": msg.channel}, function(err, connected_users_channel) {
if(connected_users_channel.length > 0 && connected_users_channel[0].users.indexOf(msg.guid) > -1) {
if(msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
if(coll.indexOf("?") > -1){
coll = coll.substring(0, coll.indexOf("?"));
}
@@ -111,9 +114,7 @@ module.exports = function() {
guid = msg.guid;
socketid = msg.socket_id;
socket.zoff_id = socketid;
if(msg.hasOwnProperty("channel")) {
msg.channel = Functions.encodeChannelName(msg.channel);
}
in_list = true;
chromecast_object = true;
socket.join(coll);
@@ -139,8 +140,8 @@ module.exports = function() {
}
coll = Functions.removeEmojis(_list).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
msg.channel = Functions.encodeChannelName(msg.channel);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -249,7 +250,7 @@ module.exports = function() {
if(channel != "") coll = channel;
if(coll !== undefined) {
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
db.collection("connected_users").findAndModify({
query: {"_id": coll},
update: {$pull: {users: guid}},
@@ -397,7 +398,7 @@ module.exports = function() {
coll = Functions.removeEmojis(_list).toLowerCase();
//coll = coll.replace(/_/g, "");
//
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -425,7 +426,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -460,7 +461,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -482,7 +483,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -506,7 +507,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -571,7 +572,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -601,7 +602,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -631,7 +632,7 @@ module.exports = function() {
if(msg.hasOwnProperty("channel") && msg.channel != "" && typeof(msg.channel) == "string") {
coll = msg.channel;//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
List.left_channel(coll, guid, short_id, in_list, socket, false);
}
})
@@ -670,7 +671,7 @@ module.exports = function() {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}

View File

@@ -60,7 +60,7 @@ function list(msg, guid, coll, offline, socket) {
}
coll = msg.channel.toLowerCase(); //.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
var pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
if(frontpage_lists.length == 1) {
@@ -129,7 +129,7 @@ function skip(list, guid, coll, offline, socket) {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}

View File

@@ -537,7 +537,7 @@ function add_function(arr, coll, guid, offline, socket) {
}
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
@@ -601,7 +601,7 @@ function add_function(arr, coll, guid, offline, socket) {
}
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
@@ -674,7 +674,7 @@ function add_function(arr, coll, guid, offline, socket) {
var coll = Functions.removeEmojis(params.channel).toLowerCase();
//coll = coll.replace(/_/g, "").replace(/ /g,'');
coll = filter.clean(coll);
//coll = filter.clean(coll);
db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(params.adminpass),true)))
{
@@ -723,7 +723,7 @@ function add_function(arr, coll, guid, offline, socket) {
}
//coll = coll.replace(/ /g,'');
coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll);
//coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;

View File

@@ -36,7 +36,7 @@ function password(inp, coll, guid, offline, socket) {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}
@@ -100,7 +100,7 @@ function conf_function(params, coll, guid, offline, socket) {
coll = Functions.removeEmojis(coll).toLowerCase();
//coll = coll.replace(/_/g, "");
coll = filter.clean(coll);
//coll = filter.clean(coll);
} catch(e) {
return;
}

View File

@@ -1,7 +1,8 @@
var path = require('path');
var time_regex = /P((([0-9]*\.?[0-9]*)Y)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)W)?(([0-9]*\.?[0-9]*)D)?)?(T(([0-9]*\.?[0-9]*)H)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)S)?)?/;
try {
var key = require(path.join(__dirname, '../config/api_key.js'));
var keys = require(path.join(__dirname, '../config/api_key.js'));
var key = keys.youtube;
} catch(e) {
console.log("Error - missing file");
console.log("Seems you forgot to create the file api_key.js in /server/config/. Have a look at api_key.example.js.");

View File

@@ -31,8 +31,12 @@ $(document).on("click", "#refresh_all", function(e){
function decodeChannelName(str) {
var _fn = decodeURIComponent;
str = str.toUpperCase();
var toReturn = _fn(str.replace(/%5F/g, "_"));
return toReturn.toLowerCase();
try {
var toReturn = _fn(str.replace(/%5F/g, "_"));
return toReturn.toLowerCase();
} catch(e) {
return str.toLowerCase();
}
}
socket.on("spread_listeners", function(obj){

View File

@@ -3096,6 +3096,10 @@ nav ul li:hover, nav ul li.active {
width: 100vw;
}
#search-wrapper:hover, #song-title:hover {
background: inherit;
}
#toast-container{
left:0% !important;
width:100vw;

View File

@@ -16,10 +16,13 @@ var Channel = {
Helper.addClass(".pagination-results", "client-pagination-height");
Helper.addClass(".control-list", "client-control-list");
} else {
SC.initialize({
client_id: '***REMOVED***'
}, function() {
});
if(!api_key.hasOwnProperty("soundcloud")) soundcloud_enabled = false;
else {
SC.initialize({
client_id: api_key.soundcloud
}, function() {
});
}
if(cast_ready_connect || chromecastAvailable || chromecastReady) {
Helper.addClass(".volume-container", "volume-container-cast");
}

View File

@@ -6,6 +6,7 @@ var paused = false;
var client = false;
var startTime = 0;
var hostMode = false;
var soundcloud_enabled = true;
var socket_connected = false;
var dynamicListeners = {};
var player_ready = false;
@@ -54,7 +55,7 @@ var Crypt = {
};
SC.initialize({
client_id: '***REMOVED***'
client_id: api_key.soundcloud
}, function() {
});

View File

@@ -254,7 +254,7 @@ var List = {
Helper.ajax({
method: "get",
url: 'https://www.googleapis.com/youtube/v3/videos?id=' + full_playlist[i].id
+ "&key=" + api_key + "&part=snippet",
+ "&key=" + api_key.youtube + "&part=snippet",
success: function (data) {
data = JSON.parse(data);
//Helper.log("Empty-checker items " + data.items.length);
@@ -813,7 +813,7 @@ var List = {
exportToYoutube: function() {
ga('send', 'event', "export", "youtube");
var request_url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&key=" + api_key;
var request_url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&key=" + api_key.youtube;
Helper.removeClass(".exported-list-container", "hide");
Helper.removeClass("#playlist_loader_export", "hide");
Helper.ajax({
@@ -833,7 +833,7 @@ var List = {
response = JSON.parse(response);
var number_added = 0;
var playlist_id = response.id;
var request_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key=" + api_key;
var request_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key=" + api_key.youtube;
List.addToYoutubePlaylist(playlist_id, full_playlist, number_added, request_url)
},
error: function(response){
@@ -902,12 +902,12 @@ var List = {
if(full_playlist[num].hasOwnProperty("source") && full_playlist[num].source != "soundcloud") {
List.insertInYouTubePlaylist(playlist_id, full_playlist[num].id, num, request_url)
} else {
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key.youtube+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";
yt_url+="&q="+full_playlist[num].title;
var title = full_playlist[num].title;
var temptitle = title.split("-");
temptitle = temptitle.join(" ").split(" ");
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key.youtube+"&id=";
Helper.ajax({
type: "GET",
url: yt_url,

View File

@@ -5,6 +5,7 @@ var client = false;
if(domain.length > 0 && domain[0] == "client") {
client = true;
}
var soundcloud_enabled = true;
var local_new_channel = false;
var hiddenPlaylist = false;
var videoSource;

View File

@@ -245,6 +245,10 @@ var Player = {
//Playercontrols.play_pause();
} else {
if(videoSource == "soundcloud") {
if(!soundcloud_enabled) {
console.error("SoundCloud isn't enabled, so can't search on SoundCloud..");
return;
}
Player.soundcloud_player.play();
//SC.Widget(document.querySelector("#soundcloud_player")).play();
} else {
@@ -264,6 +268,10 @@ var Player = {
} else {
paused = true;
if(videoSource == "soundcloud") {
if(!soundcloud_enabled) {
console.error("SoundCloud isn't enabled, so can't search on SoundCloud..");
return;
}
Player.soundcloud_player.pause();
//SC.Widget(document.querySelector("#soundcloud_player")).pause();
} else {
@@ -283,6 +291,10 @@ var Player = {
},
loadSoundCloud: function(id, this_duration, start, end, _autoplay) {
if(!soundcloud_enabled) {
console.error("SoundCloud isn't enabled, so can't search on SoundCloud..");
return;
}
try {
if(SC == null) return;
} catch(e) {

View File

@@ -44,14 +44,14 @@ var Search = {
if(search_input !== ""){
searching = true;
var keyword= encodeURIComponent(search_input);
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key+"&videoEmbeddable=true&part=id&type=video&order=relevance&safeSearch=none&maxResults=25";
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key.youtube+"&videoEmbeddable=true&part=id&type=video&order=relevance&safeSearch=none&maxResults=25";
yt_url+="&q="+keyword;
if(music)yt_url+="&videoCategoryId=10";
if(pagination) yt_url += "&pageToken=" + pagination;
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key.youtube+"&id=";
if(related) {
var yt_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&relatedToVideoId="+keyword+"&type=video&key="+api_key;
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
var yt_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&relatedToVideoId="+keyword+"&type=video&key="+api_key.youtube;
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key.youtube+"&id=";
}
Helper.addClass(document.querySelector("#search-btn .material-icons"), "hide");
@@ -196,6 +196,11 @@ var Search = {
},
soundcloudSearch: function(keyword) {
if(!soundcloud_enabled) {
document.querySelector("#results_soundcloud").innerHTML = '<div style="display:block;" id="inner-results" class="empty-inner-results"><div id="empty-results" class="valign-wrapper><span class="valign">No SoundCloud API-key, search disabled..</span></div></div>';
return;
}
if(keyword.length == 0) return;
SC.get('/tracks', {
q: keyword
@@ -308,9 +313,9 @@ var Search = {
backgroundSearch: function(title, artist, length, totalNumber, current){
var keyword= encodeURIComponent(title + " " + artist);
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+api_key.youtube+"&videoEmbeddable=true&part=id,snippet&fields=items(id,snippet)&type=video&order=relevance&safeSearch=none&maxResults=10&videoCategoryId=10";
yt_url+="&q="+keyword;
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key.youtube+"&id=";
artist = artist.split(" ");
var temptitle = title.split("-");
temptitle = temptitle.join(" ").split(" ");
@@ -454,7 +459,7 @@ importPlaylist: function(pId,pageToken){
var datatype;
if(pageToken !== undefined)
token = "&pageToken="+pageToken;
playlist_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+api_key+"&playlistId="+pId+token;
playlist_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=49&key="+api_key.youtube+"&playlistId="+pId+token;
if(youtube_authenticated) {
datatype = "html";
headers = {
@@ -597,7 +602,7 @@ importSpotifyPlaylist: function(url){
addVideos: function(ids){
var more = false;
var next_ids = [];
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=" + api_key + "&id=";
var request_url="https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=" + api_key.youtube + "&id=";
for(var i = 0; i < ids.length; i++) {
if(i > 48) {
more = true;

View File

@@ -53,8 +53,8 @@ var Suggestions = {
Helper.removeClass(document.querySelector(".suggest-title-info"), "hide");
Helper.removeClass("#suggest-song-html", "hide");
}
var get_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+id+"&type=video&key="+api_key;
var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key+"&id=";
var get_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+id+"&type=video&key="+api_key.youtube;
var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+api_key.youtube+"&id=";
Helper.ajax({
type: "GET",

View File

@@ -48,5 +48,5 @@
<a href="#" class="btn waves-effect waves-light next-results-button orange">Next</a>
</div>
</div>
<div id="results_soundcloud" class="col s12">Test 2</div>
<div id="results_soundcloud" class="col s12"></div>
</div>