io.on('connection', function (client) {
var sessionID = client.conn.request.sessionID;
var session = client.conn.request.session;
//Process Session
if (!session.clouds) {
session.clouds = Storages.getTemplate(); //an object like : {"Gdrive":{displayName:"..",url:".."},"..":{displayName:"..","url":".."}}
session.selectedCloud = "GDrive";
//config
session.config = {
clientDownload: {
value: false,
displayName: "Stream downloads to user",
type: "checkbox",
title: "Choose whether to stream file to client while catching downloads or not, if unchecked windows will close after download is captured."
},
csHead: {
value: true,
displayName: "Show cloud selection button in main menu",
type: "checkbox"
},
askForName: {
value: true,
displayName: "Ask for filename when uploading files",
type: "checkbox"
}
}
session.save();
}
//send config
client.emit('setObj', {
name: "config",
value: session.config
})
//send clouds
client.emit('setObj', {
name: 'clouds',
value: session.clouds
});
client.emit('setObj', {
name: 'selectedCloud',
value: session.clouds[session.selectedCloud]
});
//send downloads
client.emit('setObj', {
name: 'visitedPages',
value: visitedPages
});
//send torrrents
client.emit('setObj', {
name: 'torrents',
value: torrents
});
client.emit('setObj', {
name: 'incognito',
value: session.incognito ? session.incognito : false
});
client.on('clearVisitedPages', () => {
Object.keys(visitedPages).forEach((id) => {
clearVisitedPage(id);
});
});
client.on('clearTorrents', () => {
Object.keys(torrents).forEach((id) => {
clearTorrent(id);
});
});
client.on('delete', data => {
data.isTorrent ? clearTorrent(data.id) : clearVisitedPage(data.id);
});
client.on('saveToDrive', (data) => {
saveToDriveHandler(session, data);
});
client.on('pin', (data) => {
if (data.isTorrent) {
torrents[data.page.id].pinned = true;
sendTorrentsUpdate(io, data.page.id, ["pinned"]);
return false;
}
visitedPages[data.page.id].pinned = true;
sendVisitedPagesUpdate(io, data.page.id, ["pinned"]);
});
client.on('unpin', (data) => {
if (data.isTorrent) {
torrents[data.page.id].pinned = false;
sendTorrentsUpdate(io, data.page.id, ["pinned"]);
return false;
}
visitedPages[data.page.id].pinned = false;
sendVisitedPagesUpdate(io, data.page.id, ["pinned"]);
});
client.on('pirateSearch', (data) => {
var query = data.query;
var page = data.page;
scrapeIt(`https://thepiratebay.org/search/${encodeURIComponent(query)}/${page}/7/0`, {
result: {
listItem: "tr:not(.header)",
data: {
name: "a.detLink",
size: {
selector: ".detDesc",
//.........这里部分代码省略.........
请发表评论