Beispiel #1
0
 it('should return true with valid urls', function () {
     expect(subject.isUrl('http://www.thing.com')).toBeTruthy();
     expect(subject.isUrl('https://www.thing.com')).toBeTruthy();
     expect(subject.isUrl('https://www.thing.london')).toBeTruthy();
     expect(subject.isUrl('https://thing.london')).toBeTruthy();
 });
Beispiel #2
0
function add_function(arr, coll, guid, offline, socket) {
    var socketid = socket.zoff_id;
    if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration)))
    {
        if(coll == "" || coll == undefined || coll == null || !arr.hasOwnProperty("duration")) {
            var result = {
                start: {
                    expected: "number or string that can be cast to int",
                    got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
                },
                end: {
                    expected: "number or string that can be cast to int",
                    got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
                }
            };
            socket.emit('update_required', result);
            return;
        }

        try {
            if(arr.start == undefined) arr.start = 0;
            if(arr.end == undefined) arr.end = parseInt(arr.duration);
            var start = parseInt(arr.start);
            var end = parseInt(arr.end);
            if(start < 0) {
                socket.emit("toast", "faulty_start_end");
                return;
            }
            if(end < 0) {
                socket.emit("toast", "faulty_start_end");
                return;
            }
            if(start >= end) {
                start = 0;
                arr.duration = end - start;
            }
        } catch(e) {
            return;
        }

        if(!arr.hasOwnProperty("source")) {
            arr.source = "youtube";
        }

        if(typeof(arr.id) != "string" || typeof(arr.start) != "number" ||
        typeof(arr.end) != "number" || typeof(arr.title) != "string" ||
        typeof(arr.list) != "string" || typeof(arr.duration) != "number" ||
        (arr.source == "soundcloud" && (!arr.hasOwnProperty("thumbnail") || !Functions.isUrl(arr.thumbnail)))) {
            var result = {
                start: {
                    expected: "number or string that can be cast to int",
                    got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
                },
                end: {
                    expected: "number or string that can be cast to int",
                    got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
                },
                title: {
                    expected: "string",
                    got: arr.hasOwnProperty("title") ? typeof(arr.title) : undefined
                },
                list: {
                    expected: "string",
                    got: arr.hasOwnProperty("list") ? typeof(arr.list) : undefined
                },
                duration: {
                    expected: "number or string that can be cast to int",
                    got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined
                },
                pass: {
                    expected: "string",
                    got: arr.hasOwnProperty("pass") ? typeof(arr.pass) : undefined
                },
                adminpass: {
                    expected: "string",
                    got: arr.hasOwnProperty("adminpass") ? typeof(arr.adminpass) : undefined
                },
                source: {
                    expected: "string (youtube or soundcloud)",
                    got: arr.hasOwnProperty("source") ? typeof(arr.source) : undefined
                },
                thumbnail: {
                    expected: "url if source == soundcloud",
                    got: arr.hasOwnProperty("thumbnail") ? typeof(arr.thumbnail) : undefined
                }
            };
            socket.emit('update_required', result);
            return;
        }
        if(arr.hasOwnProperty("offsiteAdd") && arr.offsiteAdd) {
            coll = arr.list;
        }
        Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
            if(adminpass != "" || arr.adminpass == undefined) {
                arr.adminpass = Functions.hash_pass(adminpass);
            } else {
                arr.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true));
            }
            if(userpass != "" || arr.pass == undefined) {
                arr.pass = userpass;
            } else {
                arr.pass = crypto.createHash('sha256').update(Functions.decrypt_string(arr.pass)).digest("base64");
            }
            db.collection(coll + "_settings").find(function(err, docs){
                if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == arr.pass))) {
                    if((arr.hasOwnProperty("offsiteAdd") && !arr.offsiteAdd) || !arr.hasOwnProperty("offsiteAdd")) {
                        Functions.check_inlist(coll, guid, socket, offline, undefined, "place 5");
                    }
                    var id = arr.id + "";
                    var title = arr.title;
                    var hash = arr.adminpass;
                    var duration = parseInt(arr.duration);
                    var source = arr.source;
                    var tags = arr.tags;
                    conf = docs;
                    if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
                    docs[0].addsongs === false)) {
                        db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
                            if(docs !== null && docs.length === 0) {
                                var guids = [guid];
                                var added = Functions.get_time();
                                var votes = 1;
                                db.collection(coll).find({now_playing:true}, function(err, docs){
                                    if((docs !== null && docs.length === 0)){
                                        np = true;
                                    } else {
                                        np = false;
                                    }
                                    var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"tags":tags,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video", "source": source};
                                    if(source == "soundcloud") {
                                        if(arr.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || arr.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
                                            new_song.thumbnail = arr.thumbnail;
                                        } else {
                                            new_song.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
                                        }
                                    } else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
                                    db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
                                        new_song._id = "asd";
                                        if(np) {
                                            List.send_list(coll, undefined, false, true, false);
                                            db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
                                            List.send_play(coll, undefined);
                                            var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined;
                                            Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source);
                                            if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
                                            else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
                                        } else {
                                            io.to(coll).emit("channel", {type: "added", value: new_song});
                                            if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
                                            else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
                                        }
                                        db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
                                        List.getNextSong(coll, undefined);
                                    });
                                    socket.emit("toast", "addedsong");
                                });
                            } else {
                                vote(coll, id, guid, socket);
                            }
                        });
                    } else {
                        db.collection(coll).find({id: id}, function(err, docs) {
                            if(docs.length === 0) {
                                var suggestedAdd = {
                                    "added":Functions.get_time(),
                                    "guids": [guid],
                                    "id":id,
                                    "now_playing": false,
                                    "title":title,
                                    "votes":1,
                                    "duration":duration,
                                    "start": start,
                                    "end": end,
                                    "type":"suggested",
                                    "tags":tags
                                };
                                var source = arr.source;
                                if(source == "soundcloud") {
                                    suggestedAdd.thumbnail = arr.thumbnail;
                                    suggestedAdd.source = source;
                                } else {
                                    suggestedAdd.source = "youtube";
                                }
                                db.collection(coll).update({id: id}, {$set: suggestedAdd}, {upsert:true}, function(err, docs){
                                    socket.emit("toast", "suggested");
                                    var toSend = suggestedAdd;
                                    toSend.guids = [];
                                    if(source == "soundcloud") toSend.thumbnail = arr.thumbnail;
                                    io.to(coll).emit("suggested", toSend);
                                });
                            } else if(docs[0].now_playing === true){
                                socket.emit("toast", "alreadyplay");
                            } else{
                                if(conf[0].vote === false) vote(coll, id, guid, socket);
                                else socket.emit("toast", "listhaspass");
                            }
                        });
                    }
                } else {
                    if((arr.hasOwnProperty("offsiteAdd") && !arr.offsiteAdd) || !arr.hasOwnProperty("offsiteAdd")) {
                        socket.emit("auth_required");
                    } else {
                        socket.emit("toast", "listhaspass");
                    }
                }
            });
        });
    } else {
        var result = {
            arr: {
                expected: "object",
                got: typeof(arr)
            },
            duration: {
                expected: "number or string that can be cast to int",
                got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined,
            }
        };
        socket.emit('update_required', result);
    }
}
Beispiel #3
0
 it('should return false with invalid urls', function () {
     expect(subject.isUrl('htt://www.thing.com')).toBeFalsy();
     expect(subject.isUrl('no')).toBeFalsy();
 });
Beispiel #4
0
function thumbnail(msg, coll, guid, offline, socket) {
    if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){
        if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
             {
                var result = {
                    channel: {
                        expected: "string",
                        got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
                    },
                    pass: {
                        expected: "string",
                        got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
                    },
                    thumbnail: {
                        expected: "string",
                        got: msg.hasOwnProperty("thumbnail") ? typeof(msg.thumbnail) : undefined,
                    },
                    adminpass: {
                        expected: "string",
                        got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
                    },
                };
                socket.emit("update_required", result);
                return;
            }
            //coll = coll.replace(/ /g,'');
        Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
            if(userpass != "" || msg.pass == undefined) {
                msg.pass = userpass;
            } else if(msg.hasOwnProperty("pass")){
                msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
            }
            if(adminpass != "" || msg.adminpass == undefined) {
                msg.adminpass = Functions.hash_pass(adminpass);
            } else {
                msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true));
            }
            if(msg.thumbnail != "") {
                msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
                if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
            }
            var channel = msg.channel.toLowerCase();
            var hash = msg.adminpass;
            db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
                if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
                    if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
                        db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){
                            Notifications.requested_change("thumbnail", msg.thumbnail, channel);
                            socket.emit("toast", "suggested_thumbnail");
                        });
                    }
                } else {
                    socket.emit("auth_required");
                }
            });
        });
    } else {
        socket.emit("toast", "thumbnail_denied");
    }
}