Fixed lint issues

This commit is contained in:
RemixDev 2021-06-05 13:58:50 +02:00
parent e3e41f775f
commit aa3670bec1
24 changed files with 220 additions and 183 deletions

24
server/dist/app.js vendored
View File

@ -2,19 +2,29 @@
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.wss = exports.app = void 0; exports.wss = exports.app = void 0;
const http_1 = __importDefault(require("http")); const http_1 = __importDefault(require("http"));
const express_1 = __importDefault(require("express")); const express_1 = __importDefault(require("express"));
const ws_1 = require("ws"); const ws_1 = require("ws");
const yargs_1 = __importDefault(require("yargs"));
const debug_1 = __importDefault(require("debug")); const debug_1 = __importDefault(require("debug"));
const helpers_1 = require("yargs/helpers");
const middlewares_1 = require("./middlewares"); const middlewares_1 = require("./middlewares");
const routes_1 = __importDefault(require("./routes")); const routes_1 = __importDefault(require("./routes"));
const port_1 = require("./helpers/port"); const port_1 = require("./helpers/port");
const server_callbacks_1 = require("./helpers/server-callbacks"); const server_callbacks_1 = require("./helpers/server-callbacks");
const register_1 = require("./routes/api/register"); const register_1 = require("./routes/api/register");
const websocket_1 = require("./websocket"); const websocket_1 = require("./websocket");
const PORT = port_1.normalizePort(process.env.PORT || '6595'); const errors_1 = require("./helpers/errors");
// TODO: Remove type assertion while keeping correct types
const argv = yargs_1.default(helpers_1.hideBin(process.argv)).options({
port: { type: 'string', default: '6595' },
host: { type: 'string', default: 'localhost' }
}).argv;
const DEEMIX_PORT = port_1.normalizePort((_a = process.env.PORT) !== null && _a !== void 0 ? _a : argv.port);
const DEEMIX_HOST = (_b = process.env.HOST) !== null && _b !== void 0 ? _b : argv.host;
const debug = debug_1.default('deemix-gui:server'); const debug = debug_1.default('deemix-gui:server');
exports.app = express_1.default(); exports.app = express_1.default();
exports.wss = new ws_1.Server({ noServer: true }); exports.wss = new ws_1.Server({ noServer: true });
@ -26,17 +36,23 @@ exports.app.use('/', routes_1.default);
/* === APIs === */ /* === APIs === */
register_1.registerApis(exports.app); register_1.registerApis(exports.app);
/* === Config === */ /* === Config === */
exports.app.set('port', PORT); exports.app.set('port', DEEMIX_PORT);
/* === Server port === */ /* === Server port === */
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
server.listen(PORT); server.listen({ port: DEEMIX_PORT, host: DEEMIX_HOST });
} }
websocket_1.registerWebsocket(exports.wss); websocket_1.registerWebsocket(exports.wss);
/* === Server callbacks === */ /* === Server callbacks === */
exports.app.on('mount', a => {
console.log(a);
});
server.on('connect', () => {
errors_1.consoleInfo('Server connected');
});
server.on('upgrade', (request, socket, head) => { server.on('upgrade', (request, socket, head) => {
exports.wss.handleUpgrade(request, socket, head, socket => { exports.wss.handleUpgrade(request, socket, head, socket => {
exports.wss.emit('connection', socket, request); exports.wss.emit('connection', socket, request);
}); });
}); });
server.on('error', server_callbacks_1.getErrorCb(PORT)); server.on('error', server_callbacks_1.getErrorCb(DEEMIX_PORT));
server.on('listening', server_callbacks_1.getListeningCb(server, debug)); server.on('listening', server_callbacks_1.getListeningCb(server, debug));

View File

@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.NotLoggedIn = exports.AlreadyInQueue = exports.QueueError = exports.isBadRequestError = exports.BadRequestError = exports.consoleError = exports.consoleInfo = void 0; exports.NotLoggedIn = exports.AlreadyInQueue = exports.QueueError = exports.isBadRequestError = exports.BadRequestError = exports.consoleError = exports.consoleInfo = void 0;
const ramda_1 = require("ramda"); const ramda_1 = require("ramda");
const prependDeemix = ramda_1.concat('[deemix-server]: '); const prependDeemix = ramda_1.concat('[deemix-server]: ');
const consoleInfo = (errorText) => console.info(prependDeemix(errorText)); const consoleInfo = (infoText) => console.info(prependDeemix(infoText));
exports.consoleInfo = consoleInfo; exports.consoleInfo = consoleInfo;
const consoleError = (errorText) => console.error(prependDeemix(errorText)); const consoleError = (errorText) => console.error(prependDeemix(errorText));
exports.consoleError = consoleError; exports.consoleError = consoleError;

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.getListeningCb = exports.getErrorCb = void 0; exports.getListeningCb = exports.getErrorCb = void 0;
const errors_1 = require("./errors");
/** /**
* Event listener for HTTP server "error" event. * Event listener for HTTP server "error" event.
* *
@ -38,7 +39,8 @@ function getListeningCb(server, debug) {
const addr = server.address(); const addr = server.address();
if (addr) { if (addr) {
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind); debug(`Listening on ${bind}`);
errors_1.consoleInfo(`Listening on ${bind}`);
} }
}; };
} }

121
server/dist/main.js vendored
View File

@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreQueueFromDisk = exports.clearCompletedDownloads = exports.cancelAllDownloads = exports.cancelDownload = exports.startQueue = exports.addToQueue = exports.currentJob = exports.queue = exports.queueOrder = exports.saveSettings = exports.getSettings = exports.listener = exports.plugins = exports.getArlFromAccessToken = exports.getAccessToken = exports.sessionDZ = exports.settings = exports.configFolder = exports.defaultSettings = void 0; exports.restoreQueueFromDisk = exports.clearCompletedDownloads = exports.cancelAllDownloads = exports.cancelDownload = exports.startQueue = exports.addToQueue = exports.getQueue = exports.saveSettings = exports.getSettings = exports.listener = exports.plugins = exports.getArlFromAccessToken = exports.getAccessToken = exports.sessionDZ = exports.configFolder = exports.defaultSettings = void 0;
const fs_1 = __importDefault(require("fs")); const fs_1 = __importDefault(require("fs"));
const path_1 = require("path"); const path_1 = require("path");
const uuid_1 = require("uuid"); const uuid_1 = require("uuid");
@ -25,11 +25,12 @@ const Downloader = deemix_1.default.downloader.Downloader;
const { Single, Collection, Convertable } = deemix_1.default.types.downloadObjects; const { Single, Collection, Convertable } = deemix_1.default.types.downloadObjects;
exports.defaultSettings = deemix_1.default.settings.DEFAULTS; exports.defaultSettings = deemix_1.default.settings.DEFAULTS;
exports.configFolder = deemix_1.default.utils.localpaths.getConfigFolder(); exports.configFolder = deemix_1.default.utils.localpaths.getConfigFolder();
exports.settings = deemix_1.default.settings.load(exports.configFolder);
exports.sessionDZ = {}; exports.sessionDZ = {};
let settings = deemix_1.default.settings.load(exports.configFolder);
exports.getAccessToken = deemix_1.default.utils.deezer.getAccessToken; exports.getAccessToken = deemix_1.default.utils.deezer.getAccessToken;
exports.getArlFromAccessToken = deemix_1.default.utils.deezer.getArlFromAccessToken; exports.getArlFromAccessToken = deemix_1.default.utils.deezer.getArlFromAccessToken;
exports.plugins = { exports.plugins = {
// eslint-disable-next-line new-cap
spotify: new deemix_1.default.plugins.spotify() spotify: new deemix_1.default.plugins.spotify()
}; };
exports.plugins.spotify.setup(); exports.plugins.spotify.setup();
@ -39,7 +40,7 @@ exports.listener = {
console.log(key, data); console.log(key, data);
else else
console.log(key); console.log(key);
if (["downloadInfo", "downloadWarn"].includes(key)) if (['downloadInfo', 'downloadWarn'].includes(key))
return; return;
app_1.wss.clients.forEach(client => { app_1.wss.clients.forEach(client => {
if (client.readyState === ws_1.default.OPEN) { if (client.readyState === ws_1.default.OPEN) {
@ -49,33 +50,44 @@ exports.listener = {
} }
}; };
function getSettings() { function getSettings() {
return { settings: exports.settings, defaultSettings: exports.defaultSettings, spotifySettings: exports.plugins.spotify.getCredentials() }; return { settings, defaultSettings: exports.defaultSettings, spotifySettings: exports.plugins.spotify.getCredentials() };
} }
exports.getSettings = getSettings; exports.getSettings = getSettings;
function saveSettings(newSettings, newSpotifySettings) { function saveSettings(newSettings, newSpotifySettings) {
deemix_1.default.settings.save(newSettings, exports.configFolder); deemix_1.default.settings.save(newSettings, exports.configFolder);
exports.settings = newSettings; settings = newSettings;
exports.plugins.spotify.setCredentials(newSpotifySettings); exports.plugins.spotify.setCredentials(newSpotifySettings);
} }
exports.saveSettings = saveSettings; exports.saveSettings = saveSettings;
exports.queueOrder = []; let queueOrder = [];
exports.queue = {}; const queue = {};
exports.currentJob = null; let currentJob = null;
restoreQueueFromDisk(); restoreQueueFromDisk();
function getQueue() {
const result = {
queue,
queueOrder
};
if (currentJob && currentJob !== true) {
result.current = currentJob.downloadObject.getSlimmedDict();
}
return result;
}
exports.getQueue = getQueue;
function addToQueue(dz, url, bitrate) { function addToQueue(dz, url, bitrate) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!dz.logged_in) if (!dz.logged_in)
throw new errors_1.NotLoggedIn(); throw new errors_1.NotLoggedIn();
let downloadObjs = []; let downloadObjs = [];
let link = ""; let link = '';
const requestUUID = uuid_1.v4(); const requestUUID = uuid_1.v4();
if (url.length > 1) { if (url.length > 1) {
exports.listener.send("startGeneratingItems", { uuid: requestUUID, total: url.length }); exports.listener.send('startGeneratingItems', { uuid: requestUUID, total: url.length });
} }
for (let i = 0; i < url.length; i++) { for (let i = 0; i < url.length; i++) {
link = url[i]; link = url[i];
console.log(`Adding ${link} to queue`); console.log(`Adding ${link} to queue`);
let downloadObj = yield deemix_1.default.generateDownloadObject(dz, link, bitrate, exports.plugins, exports.listener); const downloadObj = yield deemix_1.default.generateDownloadObject(dz, link, bitrate, exports.plugins, exports.listener);
if (Array.isArray(downloadObj)) { if (Array.isArray(downloadObj)) {
downloadObjs = downloadObjs.concat(downloadObj); downloadObjs = downloadObjs.concat(downloadObj);
} }
@ -84,12 +96,12 @@ function addToQueue(dz, url, bitrate) {
} }
} }
if (url.length > 1) { if (url.length > 1) {
exports.listener.send("finishGeneratingItems", { uuid: requestUUID, total: downloadObjs.length }); exports.listener.send('finishGeneratingItems', { uuid: requestUUID, total: downloadObjs.length });
} }
const slimmedObjects = []; const slimmedObjects = [];
downloadObjs.forEach((downloadObj, pos) => { downloadObjs.forEach((downloadObj, pos) => {
// Check if element is already in queue // Check if element is already in queue
if (Object.keys(exports.queue).includes(downloadObj.uuid)) { if (Object.keys(queue).includes(downloadObj.uuid)) {
exports.listener.send('alreadyInQueue', downloadObj.getEssentialDict()); exports.listener.send('alreadyInQueue', downloadObj.getEssentialDict());
delete downloadObjs[pos]; delete downloadObjs[pos];
return; return;
@ -97,16 +109,16 @@ function addToQueue(dz, url, bitrate) {
// Save queue status when adding something to the queue // Save queue status when adding something to the queue
if (!fs_1.default.existsSync(exports.configFolder + 'queue')) if (!fs_1.default.existsSync(exports.configFolder + 'queue'))
fs_1.default.mkdirSync(exports.configFolder + 'queue'); fs_1.default.mkdirSync(exports.configFolder + 'queue');
exports.queueOrder.push(downloadObj.uuid); queueOrder.push(downloadObj.uuid);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
exports.queue[downloadObj.uuid] = downloadObj.getEssentialDict(); queue[downloadObj.uuid] = downloadObj.getEssentialDict();
exports.queue[downloadObj.uuid].status = 'inQueue'; queue[downloadObj.uuid].status = 'inQueue';
const savedObject = downloadObj.toDict(); const savedObject = downloadObj.toDict();
savedObject.status = 'inQueue'; savedObject.status = 'inQueue';
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject));
slimmedObjects.push(downloadObj.getSlimmedDict()); slimmedObjects.push(downloadObj.getSlimmedDict());
}); });
const isSingleObject = downloadObjs.length == 1; const isSingleObject = downloadObjs.length === 1;
if (isSingleObject) if (isSingleObject)
exports.listener.send('addedToQueue', downloadObjs[0].getSlimmedDict()); exports.listener.send('addedToQueue', downloadObjs[0].getSlimmedDict());
else else
@ -119,14 +131,14 @@ exports.addToQueue = addToQueue;
function startQueue(dz) { function startQueue(dz) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
do { do {
if (exports.currentJob !== null || exports.queueOrder.length === 0) { if (currentJob !== null || queueOrder.length === 0) {
// Should not start another download // Should not start another download
return null; return null;
} }
exports.currentJob = true; // lock currentJob currentJob = true; // lock currentJob
const currentUUID = exports.queueOrder.shift() || ''; const currentUUID = queueOrder.shift() || '';
console.log(currentUUID); console.log(currentUUID);
exports.queue[currentUUID].status = 'downloading'; queue[currentUUID].status = 'downloading';
const currentItem = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}${currentUUID}.json`).toString()); const currentItem = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}${currentUUID}.json`).toString());
let downloadObject; let downloadObject;
switch (currentItem.__type__) { switch (currentItem.__type__) {
@ -138,79 +150,80 @@ function startQueue(dz) {
break; break;
case 'Convertable': case 'Convertable':
downloadObject = new Convertable(currentItem); downloadObject = new Convertable(currentItem);
downloadObject = yield exports.plugins[downloadObject.plugin].convert(dz, downloadObject, exports.settings, exports.listener); downloadObject = yield exports.plugins[downloadObject.plugin].convert(dz, downloadObject, settings, exports.listener);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`, JSON.stringify(Object.assign(Object.assign({}, downloadObject.toDict()), { status: 'inQueue' }))); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`, JSON.stringify(Object.assign(Object.assign({}, downloadObject.toDict()), { status: 'inQueue' })));
break; break;
} }
exports.currentJob = new Downloader(dz, downloadObject, exports.settings, exports.listener); currentJob = new Downloader(dz, downloadObject, settings, exports.listener);
exports.listener.send('startDownload', currentUUID); exports.listener.send('startDownload', currentUUID);
yield exports.currentJob.start(); yield currentJob.start();
if (!downloadObject.isCanceled) { if (!downloadObject.isCanceled) {
// Set status // Set status
if (downloadObject.failed == downloadObject.size) { if (downloadObject.failed === downloadObject.size) {
exports.queue[currentUUID].status = 'failed'; queue[currentUUID].status = 'failed';
} }
else if (downloadObject.failed > 0) { else if (downloadObject.failed > 0) {
exports.queue[currentUUID].status = 'withErrors'; queue[currentUUID].status = 'withErrors';
} }
else { else {
exports.queue[currentUUID].status = 'completed'; queue[currentUUID].status = 'completed';
} }
const savedObject = downloadObject.getSlimmedDict(); const savedObject = downloadObject.getSlimmedDict();
savedObject.status = exports.queue[currentUUID].status; savedObject.status = queue[currentUUID].status;
// Save queue status // Save queue status
exports.queue[currentUUID] = savedObject; queue[currentUUID] = savedObject;
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${currentUUID}.json`, JSON.stringify(savedObject)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${currentUUID}.json`, JSON.stringify(savedObject));
} }
console.log(exports.queueOrder); console.log(queueOrder);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
exports.currentJob = null; currentJob = null;
} while (exports.queueOrder.length); } while (queueOrder.length);
}); });
} }
exports.startQueue = startQueue; exports.startQueue = startQueue;
function cancelDownload(uuid) { function cancelDownload(uuid) {
if (Object.keys(exports.queue).includes(uuid)) { if (Object.keys(queue).includes(uuid)) {
switch (exports.queue[uuid].status) { switch (queue[uuid].status) {
case 'downloading': case 'downloading':
exports.currentJob.downloadObject.isCanceled = true; currentJob.downloadObject.isCanceled = true;
exports.listener.send('cancellingCurrentItem', uuid); exports.listener.send('cancellingCurrentItem', uuid);
break; break;
case 'inQueue': case 'inQueue':
exports.queueOrder.splice(exports.queueOrder.indexOf(uuid), 1); queueOrder.splice(queueOrder.indexOf(uuid), 1);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
// break // break
// eslint-disable-next-line no-fallthrough
default: default:
// This gets called even in the 'inQueue' case. Is this the expected behaviour? If no, de-comment the break // This gets called even in the 'inQueue' case. Is this the expected behaviour? If no, de-comment the break
exports.listener.send('removedFromQueue', uuid); exports.listener.send('removedFromQueue', uuid);
break; break;
} }
fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${uuid}.json`); fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${uuid}.json`);
delete exports.queue[uuid]; delete queue[uuid];
} }
} }
exports.cancelDownload = cancelDownload; exports.cancelDownload = cancelDownload;
function cancelAllDownloads() { function cancelAllDownloads() {
exports.queueOrder = []; queueOrder = [];
let currentItem = null; let currentItem = null;
Object.values(exports.queue).forEach((downloadObject) => { Object.values(queue).forEach((downloadObject) => {
if (downloadObject.status == 'downloading') { if (downloadObject.status === 'downloading') {
exports.currentJob.downloadObject.isCanceled = true; currentJob.downloadObject.isCanceled = true;
exports.listener.send('cancellingCurrentItem', downloadObject.uuid); exports.listener.send('cancellingCurrentItem', downloadObject.uuid);
currentItem = downloadObject.uuid; currentItem = downloadObject.uuid;
} }
fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`); fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`);
delete exports.queue[downloadObject.uuid]; delete queue[downloadObject.uuid];
}); });
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
exports.listener.send('removedAllDownloads', currentItem); exports.listener.send('removedAllDownloads', currentItem);
} }
exports.cancelAllDownloads = cancelAllDownloads; exports.cancelAllDownloads = cancelAllDownloads;
function clearCompletedDownloads() { function clearCompletedDownloads() {
Object.values(exports.queue).forEach((downloadObject) => { Object.values(queue).forEach((downloadObject) => {
if (downloadObject.status === 'completed') { if (downloadObject.status === 'completed') {
fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`); fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`);
delete exports.queue[downloadObject.uuid]; delete queue[downloadObject.uuid];
} }
}); });
exports.listener.send('removedFinishedDownloads'); exports.listener.send('removedFinishedDownloads');
@ -221,8 +234,8 @@ function restoreQueueFromDisk() {
fs_1.default.mkdirSync(exports.configFolder + 'queue'); fs_1.default.mkdirSync(exports.configFolder + 'queue');
const allItems = fs_1.default.readdirSync(exports.configFolder + 'queue'); const allItems = fs_1.default.readdirSync(exports.configFolder + 'queue');
allItems.forEach((filename) => { allItems.forEach((filename) => {
if (filename == 'order.json') { if (filename === 'order.json') {
exports.queueOrder = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}order.json`).toString()); queueOrder = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}order.json`).toString());
} }
else { else {
const currentItem = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}${filename}`).toString()); const currentItem = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}${filename}`).toString());
@ -239,11 +252,11 @@ function restoreQueueFromDisk() {
downloadObject = new Convertable(currentItem); downloadObject = new Convertable(currentItem);
break; break;
} }
exports.queue[downloadObject.uuid] = downloadObject.getEssentialDict(); queue[downloadObject.uuid] = downloadObject.getEssentialDict();
exports.queue[downloadObject.uuid].status = 'inQueue'; queue[downloadObject.uuid].status = 'inQueue';
} }
else { else {
exports.queue[currentItem.uuid] = currentItem; queue[currentItem.uuid] = currentItem;
} }
} }
}); });

View File

@ -13,18 +13,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
const deezer_js_1 = require("deezer-js"); const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/album-search/'; const path = '/album-search/';
const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
if (!main_1.sessionDZ[req.session.id]) if (!main_1.sessionDZ[req.session.id])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer(); main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id]; const dz = main_1.sessionDZ[req.session.id];
if (!req.query) { if (!req.query) {
res.status(400).send(); return res.status(400).send();
return next();
} }
const { term, start, nb, ack } = parseQuery(req.query); const { term, start, nb, ack } = parseQuery(req.query);
if (!term || term.trim() === '') { if (!term || term.trim() === '') {
res.status(400).send(); return res.status(400).send();
return next();
} }
const albums = yield dz.api.search_album(term, { start, nb }); const albums = yield dz.api.search_album(term, { start, nb });
const output = { const output = {
@ -32,9 +30,7 @@ const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
total: albums.data.length, total: albums.data.length,
ack ack
}; };
res.send(output); return res.send(output);
res.send();
next();
}); });
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -1 +1,46 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error
const deemix_1 = __importDefault(require("deemix"));
// @ts-expect-error
const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main");
const path = '/analyzeLink';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
if (!req.query || !req.query.term) {
return res.status(400).send({ errorMessage: 'No term specified', errorCode: 'AL01' });
}
const { term: linkToAnalyze } = req.query;
const [, linkType, linkId] = yield deemix_1.default.parseLink(linkToAnalyze);
const isTrackOrAlbum = ['track', 'album'].includes(linkType);
if (isTrackOrAlbum) {
if (!main_1.sessionDZ[req.session.id])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id];
const apiMethod = linkType === 'track' ? 'get_track' : 'get_album';
const resBody = yield dz.api[apiMethod](linkId);
return res.status(200).send(resBody);
}
return res.status(400).send({ errorMessage: 'Not supported', errorCode: 'AL02' });
}
catch (error) {
return res
.status(500)
.send({ errorMessage: 'The server had a problem. Please try again', errorObject: error, errorCode: 'AL03' });
}
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -1 +1,19 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error
const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main");
const path = '/changeAccount';
const handler = (req, res) => {
if (!req.query || !req.query.child) {
return res.status(400).send({ errorMessage: 'No child specified', errorCode: 'CA01' });
}
const { child: accountNum } = req.query;
if (!main_1.sessionDZ[req.session.id])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id];
const accountData = dz.change_account(accountNum);
return res.status(200).send(accountData);
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -4,12 +4,7 @@ const main_1 = require("../../../main");
const path = '/getQueue'; const path = '/getQueue';
// let homeCache: any // let homeCache: any
const handler = (_, res) => { const handler = (_, res) => {
const result = { const result = main_1.getQueue();
queue: main_1.queue,
order: main_1.queueOrder
};
if (main_1.currentJob)
result.currentItem = main_1.currentJob.downloadObject.getSlimmedDict();
res.send(result); res.send(result);
}; };
const apiHandler = { path, handler }; const apiHandler = { path, handler };

View File

@ -31,14 +31,14 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
if (!main_1.plugins.spotify.enabled) { if (!main_1.plugins.spotify.enabled) {
res.send({ res.send({
collaborative: false, collaborative: false,
description: "", description: '',
external_urls: { spotify: null }, external_urls: { spotify: null },
followers: { total: 0, href: null }, followers: { total: 0, href: null },
id: null, id: null,
images: [], images: [],
name: "Something went wrong", name: 'Something went wrong',
owner: { owner: {
display_name: "Error", display_name: 'Error',
id: null id: null
}, },
public: true, public: true,
@ -48,15 +48,15 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
}); });
break; break;
} }
let sp = main_1.plugins.spotify.sp; const sp = main_1.plugins.spotify.sp;
let playlist = yield sp.getPlaylist(list_id); let playlist = yield sp.getPlaylist(list_id);
playlist = playlist.body; playlist = playlist.body;
let tracklist = playlist.tracks.items; let tracklist = playlist.tracks.items;
while (playlist.tracks.next) { while (playlist.tracks.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next); const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next);
let offset = regExec[1]; const offset = regExec[1];
let limit = regExec[2]; const limit = regExec[2];
let playlistTracks = yield sp.getPlaylistTracks(list_id, { offset, limit }); const playlistTracks = yield sp.getPlaylistTracks(list_id, { offset, limit });
playlist.tracks = playlistTracks.body; playlist.tracks = playlistTracks.body;
tracklist = tracklist.concat(playlist.tracks.items); tracklist = tracklist.concat(playlist.tracks.items);
} }

View File

@ -14,16 +14,16 @@ const path = '/getUserSpotifyPlaylists';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
let data; let data;
if (main_1.plugins.spotify.enabled) { if (main_1.plugins.spotify.enabled) {
let sp = main_1.plugins.spotify.sp; const sp = main_1.plugins.spotify.sp;
const username = req.query.spotifyUser; const username = req.query.spotifyUser;
data = []; data = [];
let playlists = yield sp.getUserPlaylists(username); let playlists = yield sp.getUserPlaylists(username);
let playlistList = playlists.body.items; let playlistList = playlists.body.items;
while (playlists.next) { while (playlists.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next); const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next);
let offset = regExec[1]; const offset = regExec[1];
let limit = regExec[2]; const limit = regExec[2];
let newPlaylists = yield sp.getUserPlaylists(username, { offset, limit }); const newPlaylists = yield sp.getUserPlaylists(username, { offset, limit });
playlists = newPlaylists.body; playlists = newPlaylists.body;
playlistList = playlistList.concat(playlists.items); playlistList = playlistList.concat(playlists.items);
} }

View File

@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const analyzeLink_1 = __importDefault(require("./analyzeLink"));
const changeAccount_1 = __importDefault(require("./changeAccount"));
const getHome_1 = __importDefault(require("./getHome")); const getHome_1 = __importDefault(require("./getHome"));
const getCharts_1 = __importDefault(require("./getCharts")); const getCharts_1 = __importDefault(require("./getCharts"));
const mainSearch_1 = __importDefault(require("./mainSearch")); const mainSearch_1 = __importDefault(require("./mainSearch"));
@ -20,6 +22,8 @@ const getUserFavorites_1 = __importDefault(require("./getUserFavorites"));
const getQueue_1 = __importDefault(require("./getQueue")); const getQueue_1 = __importDefault(require("./getQueue"));
exports.default = [ exports.default = [
albumSearch_1.default, albumSearch_1.default,
changeAccount_1.default,
analyzeLink_1.default,
getHome_1.default, getHome_1.default,
getCharts_1.default, getCharts_1.default,
getChartTracks_1.default, getChartTracks_1.default,

View File

@ -20,7 +20,7 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const url = req.query.url.split(';'); const url = req.query.url.split(';');
let bitrate = req.query.bitrate; let bitrate = req.query.bitrate;
if (bitrate === 'null') if (bitrate === 'null')
bitrate = main_1.settings.maxBitrate; bitrate = main_1.getSettings().settings.maxBitrate;
let obj; let obj;
try { try {
obj = yield main_1.addToQueue(dz, url, bitrate); obj = yield main_1.addToQueue(dz, url, bitrate);

View File

@ -1,19 +1,10 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/cancelAllDownloads'; const path = '/cancelAllDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (_, res) => {
main_1.cancelAllDownloads(); main_1.cancelAllDownloads();
res.send({ result: true }); res.send({ result: true });
}); };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -20,17 +20,15 @@ const LoginStatus = {
FORCED_SUCCESS: 3 FORCED_SUCCESS: 3
}; };
const path = '/login-arl'; const path = '/login-arl';
const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res, _) => __awaiter(void 0, void 0, void 0, function* () {
if (!main_1.sessionDZ[req.session.id]) if (!main_1.sessionDZ[req.session.id])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer(); main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id]; const dz = main_1.sessionDZ[req.session.id];
if (!req.query) { if (!req.query) {
res.status(400).send(); return res.status(400).send();
return next();
} }
if (!req.query.arl) { if (!req.query.arl) {
res.status(400).send(); return res.status(400).send();
return next();
} }
const loginParams = [req.query.arl]; const loginParams = [req.query.arl];
// TODO Handle the child === 0 case, don't want to rely on the login_via_arl default param (it may change in the // TODO Handle the child === 0 case, don't want to rely on the login_via_arl default param (it may change in the
@ -52,11 +50,9 @@ const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
const testDz = new deezer_js_1.Deezer(); const testDz = new deezer_js_1.Deezer();
response = yield testDz.login_via_arl(...loginParams); response = yield testDz.login_via_arl(...loginParams);
} }
console.log(response);
const returnValue = { status: response, arl: req.query.arl, user: dz.current_user }; const returnValue = { status: response, arl: req.query.arl, user: dz.current_user };
res.status(200).send(returnValue);
main_1.startQueue(dz); main_1.startQueue(dz);
next(); return res.status(200).send(returnValue);
}); });
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -1,21 +1,12 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error // @ts-expect-error
const deezer_js_1 = require("deezer-js"); const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/logout'; const path = '/logout';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => {
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer(); main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
res.send({ logged_out: true }); res.send({ logged_out: true });
}); };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -1,19 +1,10 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/removeFinishedDownloads'; const path = '/removeFinishedDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (_, res) => {
main_1.clearCompletedDownloads(); main_1.clearCompletedDownloads();
res.send({ result: true }); res.send({ result: true });
}); };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -1,17 +1,8 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/removeFromQueue'; const path = '/removeFromQueue';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => {
const { uuid } = req.query; const { uuid } = req.query;
if (uuid) { if (uuid) {
main_1.cancelDownload(uuid); main_1.cancelDownload(uuid);
@ -20,6 +11,6 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
else { else {
res.send({ result: false }); res.send({ result: false });
} }
}); };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -1,21 +1,12 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/saveSettings'; const path = '/saveSettings';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => {
const { settings, spotifySettings } = req.query; const { settings, spotifySettings } = req.query;
main_1.saveSettings(settings, spotifySettings); main_1.saveSettings(settings, spotifySettings);
main_1.listener.send('updateSettings', { settings, spotifySettings }); main_1.listener.send('updateSettings', { settings, spotifySettings });
res.send({ result: true }); res.send({ result: true });
}); };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -31,14 +31,9 @@ router.get('/connect', (req, res) => {
currentUser: dz.current_user, currentUser: dz.current_user,
deezerNotAvailable: false deezerNotAvailable: false
}; };
if (Object.keys(main_1.queue).length > 0) { const queue = main_1.getQueue();
result.queue = { if (Object.keys(queue.queue).length > 0) {
queue: main_1.queue, result.queue = queue;
queueOrder: main_1.queueOrder
};
if (main_1.currentJob && main_1.currentJob !== true) {
result.queue.current = main_1.currentJob.downloadObject.getSlimmedDict();
}
} }
res.send(result); res.send(result);
}); });

View File

@ -12,8 +12,8 @@ const Downloader = deemix.downloader.Downloader
const { Single, Collection, Convertable } = deemix.types.downloadObjects const { Single, Collection, Convertable } = deemix.types.downloadObjects
export const defaultSettings: Settings = deemix.settings.DEFAULTS export const defaultSettings: Settings = deemix.settings.DEFAULTS
export const configFolder: string = deemix.utils.localpaths.getConfigFolder() export const configFolder: string = deemix.utils.localpaths.getConfigFolder()
export let settings: any = deemix.settings.load(configFolder)
export const sessionDZ: any = {} export const sessionDZ: any = {}
let settings: any = deemix.settings.load(configFolder)
export const getAccessToken = deemix.utils.deezer.getAccessToken export const getAccessToken = deemix.utils.deezer.getAccessToken
export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken
@ -47,12 +47,23 @@ export function saveSettings(newSettings: any, newSpotifySettings: any) {
plugins.spotify.setCredentials(newSpotifySettings) plugins.spotify.setCredentials(newSpotifySettings)
} }
export let queueOrder: string[] = [] let queueOrder: string[] = []
export const queue: any = {} const queue: any = {}
export let currentJob: any = null let currentJob: any = null
restoreQueueFromDisk() restoreQueueFromDisk()
export function getQueue() {
const result: any = {
queue,
queueOrder
}
if (currentJob && currentJob !== true) {
result.current = currentJob.downloadObject.getSlimmedDict()
}
return result
}
export async function addToQueue(dz: any, url: string[], bitrate: number) { export async function addToQueue(dz: any, url: string[], bitrate: number) {
if (!dz.logged_in) throw new NotLoggedIn() if (!dz.logged_in) throw new NotLoggedIn()
@ -146,7 +157,7 @@ export async function startQueue(dz: any): Promise<any> {
if (!downloadObject.isCanceled) { if (!downloadObject.isCanceled) {
// Set status // Set status
if (downloadObject.failed == downloadObject.size) { if (downloadObject.failed === downloadObject.size) {
queue[currentUUID].status = 'failed' queue[currentUUID].status = 'failed'
} else if (downloadObject.failed > 0) { } else if (downloadObject.failed > 0) {
queue[currentUUID].status = 'withErrors' queue[currentUUID].status = 'withErrors'

View File

@ -1,18 +1,13 @@
// import { Deezer } from 'deezer-js' // import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
import { queueOrder, queue, currentJob } from '../../../main' import { getQueue } from '../../../main'
const path: ApiHandler['path'] = '/getQueue' const path: ApiHandler['path'] = '/getQueue'
// let homeCache: any // let homeCache: any
const handler: ApiHandler['handler'] = (_, res) => { const handler: ApiHandler['handler'] = (_, res) => {
const result: any = { const result: any = getQueue()
queue,
order: queueOrder
}
if (currentJob) result.currentItem = currentJob.downloadObject.getSlimmedDict()
res.send(result) res.send(result)
} }

View File

@ -1,7 +1,7 @@
// @ts-expect-error // @ts-expect-error
import { Deezer } from 'deezer-js' import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
import { sessionDZ, addToQueue, settings, listener } from '../../../main' import { sessionDZ, addToQueue, getSettings, listener } from '../../../main'
const path: ApiHandler['path'] = '/addToQueue' const path: ApiHandler['path'] = '/addToQueue'
@ -11,7 +11,7 @@ const handler: ApiHandler['handler'] = async (req, res) => {
const url = req.query.url.split(';') const url = req.query.url.split(';')
let bitrate = req.query.bitrate let bitrate = req.query.bitrate
if (bitrate === 'null') bitrate = settings.maxBitrate if (bitrate === 'null') bitrate = getSettings().settings.maxBitrate
let obj: any let obj: any
try { try {

View File

@ -19,7 +19,7 @@ const LoginStatus = {
const path: ApiHandler['path'] = '/login-arl' const path: ApiHandler['path'] = '/login-arl'
const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, next) => { const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id] const dz = sessionDZ[req.session.id]

View File

@ -1,7 +1,7 @@
import express from 'express' import express from 'express'
// @ts-expect-error // @ts-expect-error
import { Deezer } from 'deezer-js' import { Deezer } from 'deezer-js'
import { sessionDZ, queue, queueOrder, currentJob } from '../main' import { sessionDZ, getQueue } from '../main'
const router = express.Router() const router = express.Router()
@ -30,14 +30,10 @@ router.get('/connect', (req, res) => {
deezerNotAvailable: false deezerNotAvailable: false
} }
if (Object.keys(queue).length > 0) { const queue = getQueue()
result.queue = {
queue, if (Object.keys(queue.queue).length > 0) {
queueOrder result.queue = queue
}
if (currentJob && currentJob !== true) {
result.queue.current = currentJob.downloadObject.getSlimmedDict()
}
} }
res.send(result) res.send(result)