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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wss = exports.app = void 0;
const http_1 = __importDefault(require("http"));
const express_1 = __importDefault(require("express"));
const ws_1 = require("ws");
const yargs_1 = __importDefault(require("yargs"));
const debug_1 = __importDefault(require("debug"));
const helpers_1 = require("yargs/helpers");
const middlewares_1 = require("./middlewares");
const routes_1 = __importDefault(require("./routes"));
const port_1 = require("./helpers/port");
const server_callbacks_1 = require("./helpers/server-callbacks");
const register_1 = require("./routes/api/register");
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');
exports.app = express_1.default();
exports.wss = new ws_1.Server({ noServer: true });
@ -26,17 +36,23 @@ exports.app.use('/', routes_1.default);
/* === APIs === */
register_1.registerApis(exports.app);
/* === Config === */
exports.app.set('port', PORT);
exports.app.set('port', DEEMIX_PORT);
/* === Server port === */
if (process.env.NODE_ENV !== 'test') {
server.listen(PORT);
server.listen({ port: DEEMIX_PORT, host: DEEMIX_HOST });
}
websocket_1.registerWebsocket(exports.wss);
/* === Server callbacks === */
exports.app.on('mount', a => {
console.log(a);
});
server.on('connect', () => {
errors_1.consoleInfo('Server connected');
});
server.on('upgrade', (request, socket, head) => {
exports.wss.handleUpgrade(request, socket, head, socket => {
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));

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;
const ramda_1 = require("ramda");
const prependDeemix = ramda_1.concat('[deemix-server]: ');
const consoleInfo = (errorText) => console.info(prependDeemix(errorText));
const consoleInfo = (infoText) => console.info(prependDeemix(infoText));
exports.consoleInfo = consoleInfo;
const consoleError = (errorText) => console.error(prependDeemix(errorText));
exports.consoleError = consoleError;

View file

@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getListeningCb = exports.getErrorCb = void 0;
const errors_1 = require("./errors");
/**
* Event listener for HTTP server "error" event.
*
@ -38,7 +39,8 @@ function getListeningCb(server, debug) {
const addr = server.address();
if (addr) {
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 };
};
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 path_1 = require("path");
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;
exports.defaultSettings = deemix_1.default.settings.DEFAULTS;
exports.configFolder = deemix_1.default.utils.localpaths.getConfigFolder();
exports.settings = deemix_1.default.settings.load(exports.configFolder);
exports.sessionDZ = {};
let settings = deemix_1.default.settings.load(exports.configFolder);
exports.getAccessToken = deemix_1.default.utils.deezer.getAccessToken;
exports.getArlFromAccessToken = deemix_1.default.utils.deezer.getArlFromAccessToken;
exports.plugins = {
// eslint-disable-next-line new-cap
spotify: new deemix_1.default.plugins.spotify()
};
exports.plugins.spotify.setup();
@ -39,7 +40,7 @@ exports.listener = {
console.log(key, data);
else
console.log(key);
if (["downloadInfo", "downloadWarn"].includes(key))
if (['downloadInfo', 'downloadWarn'].includes(key))
return;
app_1.wss.clients.forEach(client => {
if (client.readyState === ws_1.default.OPEN) {
@ -49,33 +50,44 @@ exports.listener = {
}
};
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;
function saveSettings(newSettings, newSpotifySettings) {
deemix_1.default.settings.save(newSettings, exports.configFolder);
exports.settings = newSettings;
settings = newSettings;
exports.plugins.spotify.setCredentials(newSpotifySettings);
}
exports.saveSettings = saveSettings;
exports.queueOrder = [];
exports.queue = {};
exports.currentJob = null;
let queueOrder = [];
const queue = {};
let currentJob = null;
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) {
return __awaiter(this, void 0, void 0, function* () {
if (!dz.logged_in)
throw new errors_1.NotLoggedIn();
let downloadObjs = [];
let link = "";
let link = '';
const requestUUID = uuid_1.v4();
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++) {
link = url[i];
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)) {
downloadObjs = downloadObjs.concat(downloadObj);
}
@ -84,12 +96,12 @@ function addToQueue(dz, url, bitrate) {
}
}
if (url.length > 1) {
exports.listener.send("finishGeneratingItems", { uuid: requestUUID, total: downloadObjs.length });
exports.listener.send('finishGeneratingItems', { uuid: requestUUID, total: downloadObjs.length });
}
const slimmedObjects = [];
downloadObjs.forEach((downloadObj, pos) => {
// 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());
delete downloadObjs[pos];
return;
@ -97,16 +109,16 @@ function addToQueue(dz, url, bitrate) {
// Save queue status when adding something to the queue
if (!fs_1.default.existsSync(exports.configFolder + 'queue'))
fs_1.default.mkdirSync(exports.configFolder + 'queue');
exports.queueOrder.push(downloadObj.uuid);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder));
exports.queue[downloadObj.uuid] = downloadObj.getEssentialDict();
exports.queue[downloadObj.uuid].status = 'inQueue';
queueOrder.push(downloadObj.uuid);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
queue[downloadObj.uuid] = downloadObj.getEssentialDict();
queue[downloadObj.uuid].status = 'inQueue';
const savedObject = downloadObj.toDict();
savedObject.status = 'inQueue';
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject));
slimmedObjects.push(downloadObj.getSlimmedDict());
});
const isSingleObject = downloadObjs.length == 1;
const isSingleObject = downloadObjs.length === 1;
if (isSingleObject)
exports.listener.send('addedToQueue', downloadObjs[0].getSlimmedDict());
else
@ -119,14 +131,14 @@ exports.addToQueue = addToQueue;
function startQueue(dz) {
return __awaiter(this, void 0, void 0, function* () {
do {
if (exports.currentJob !== null || exports.queueOrder.length === 0) {
if (currentJob !== null || queueOrder.length === 0) {
// Should not start another download
return null;
}
exports.currentJob = true; // lock currentJob
const currentUUID = exports.queueOrder.shift() || '';
currentJob = true; // lock currentJob
const currentUUID = queueOrder.shift() || '';
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());
let downloadObject;
switch (currentItem.__type__) {
@ -138,79 +150,80 @@ function startQueue(dz) {
break;
case 'Convertable':
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' })));
break;
}
exports.currentJob = new Downloader(dz, downloadObject, exports.settings, exports.listener);
currentJob = new Downloader(dz, downloadObject, settings, exports.listener);
exports.listener.send('startDownload', currentUUID);
yield exports.currentJob.start();
yield currentJob.start();
if (!downloadObject.isCanceled) {
// Set status
if (downloadObject.failed == downloadObject.size) {
exports.queue[currentUUID].status = 'failed';
if (downloadObject.failed === downloadObject.size) {
queue[currentUUID].status = 'failed';
}
else if (downloadObject.failed > 0) {
exports.queue[currentUUID].status = 'withErrors';
queue[currentUUID].status = 'withErrors';
}
else {
exports.queue[currentUUID].status = 'completed';
queue[currentUUID].status = 'completed';
}
const savedObject = downloadObject.getSlimmedDict();
savedObject.status = exports.queue[currentUUID].status;
savedObject.status = queue[currentUUID].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));
}
console.log(exports.queueOrder);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder));
exports.currentJob = null;
} while (exports.queueOrder.length);
console.log(queueOrder);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
currentJob = null;
} while (queueOrder.length);
});
}
exports.startQueue = startQueue;
function cancelDownload(uuid) {
if (Object.keys(exports.queue).includes(uuid)) {
switch (exports.queue[uuid].status) {
if (Object.keys(queue).includes(uuid)) {
switch (queue[uuid].status) {
case 'downloading':
exports.currentJob.downloadObject.isCanceled = true;
currentJob.downloadObject.isCanceled = true;
exports.listener.send('cancellingCurrentItem', uuid);
break;
case 'inQueue':
exports.queueOrder.splice(exports.queueOrder.indexOf(uuid), 1);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(exports.queueOrder));
queueOrder.splice(queueOrder.indexOf(uuid), 1);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}order.json`, JSON.stringify(queueOrder));
// break
// eslint-disable-next-line no-fallthrough
default:
// This gets called even in the 'inQueue' case. Is this the expected behaviour? If no, de-comment the break
exports.listener.send('removedFromQueue', uuid);
break;
}
fs_1.default.unlinkSync(exports.configFolder + `queue${path_1.sep}${uuid}.json`);
delete exports.queue[uuid];
delete queue[uuid];
}
}
exports.cancelDownload = cancelDownload;
function cancelAllDownloads() {
exports.queueOrder = [];
queueOrder = [];
let currentItem = null;
Object.values(exports.queue).forEach((downloadObject) => {
if (downloadObject.status == 'downloading') {
exports.currentJob.downloadObject.isCanceled = true;
Object.values(queue).forEach((downloadObject) => {
if (downloadObject.status === 'downloading') {
currentJob.downloadObject.isCanceled = true;
exports.listener.send('cancellingCurrentItem', downloadObject.uuid);
currentItem = downloadObject.uuid;
}
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.cancelAllDownloads = cancelAllDownloads;
function clearCompletedDownloads() {
Object.values(exports.queue).forEach((downloadObject) => {
Object.values(queue).forEach((downloadObject) => {
if (downloadObject.status === 'completed') {
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');
@ -221,8 +234,8 @@ function restoreQueueFromDisk() {
fs_1.default.mkdirSync(exports.configFolder + 'queue');
const allItems = fs_1.default.readdirSync(exports.configFolder + 'queue');
allItems.forEach((filename) => {
if (filename == 'order.json') {
exports.queueOrder = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}order.json`).toString());
if (filename === 'order.json') {
queueOrder = JSON.parse(fs_1.default.readFileSync(exports.configFolder + `queue${path_1.sep}order.json`).toString());
}
else {
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);
break;
}
exports.queue[downloadObject.uuid] = downloadObject.getEssentialDict();
exports.queue[downloadObject.uuid].status = 'inQueue';
queue[downloadObject.uuid] = downloadObject.getEssentialDict();
queue[downloadObject.uuid].status = 'inQueue';
}
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 main_1 = require("../../../main");
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])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id];
if (!req.query) {
res.status(400).send();
return next();
return res.status(400).send();
}
const { term, start, nb, ack } = parseQuery(req.query);
if (!term || term.trim() === '') {
res.status(400).send();
return next();
return res.status(400).send();
}
const albums = yield dz.api.search_album(term, { start, nb });
const output = {
@ -32,9 +30,7 @@ const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
total: albums.data.length,
ack
};
res.send(output);
res.send();
next();
return res.send(output);
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -1 +1,46 @@
"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";
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';
// let homeCache: any
const handler = (_, res) => {
const result = {
queue: main_1.queue,
order: main_1.queueOrder
};
if (main_1.currentJob)
result.currentItem = main_1.currentJob.downloadObject.getSlimmedDict();
const result = main_1.getQueue();
res.send(result);
};
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) {
res.send({
collaborative: false,
description: "",
description: '',
external_urls: { spotify: null },
followers: { total: 0, href: null },
id: null,
images: [],
name: "Something went wrong",
name: 'Something went wrong',
owner: {
display_name: "Error",
display_name: 'Error',
id: null
},
public: true,
@ -48,15 +48,15 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
});
break;
}
let sp = main_1.plugins.spotify.sp;
const sp = main_1.plugins.spotify.sp;
let playlist = yield sp.getPlaylist(list_id);
playlist = playlist.body;
let tracklist = playlist.tracks.items;
while (playlist.tracks.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next);
let offset = regExec[1];
let limit = regExec[2];
let playlistTracks = yield sp.getPlaylistTracks(list_id, { offset, limit });
const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next);
const offset = regExec[1];
const limit = regExec[2];
const playlistTracks = yield sp.getPlaylistTracks(list_id, { offset, limit });
playlist.tracks = playlistTracks.body;
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* () {
let data;
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;
data = [];
let playlists = yield sp.getUserPlaylists(username);
let playlistList = playlists.body.items;
while (playlists.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next);
let offset = regExec[1];
let limit = regExec[2];
let newPlaylists = yield sp.getUserPlaylists(username, { offset, limit });
const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next);
const offset = regExec[1];
const limit = regExec[2];
const newPlaylists = yield sp.getUserPlaylists(username, { offset, limit });
playlists = newPlaylists.body;
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 };
};
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 getCharts_1 = __importDefault(require("./getCharts"));
const mainSearch_1 = __importDefault(require("./mainSearch"));
@ -20,6 +22,8 @@ const getUserFavorites_1 = __importDefault(require("./getUserFavorites"));
const getQueue_1 = __importDefault(require("./getQueue"));
exports.default = [
albumSearch_1.default,
changeAccount_1.default,
analyzeLink_1.default,
getHome_1.default,
getCharts_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(';');
let bitrate = req.query.bitrate;
if (bitrate === 'null')
bitrate = main_1.settings.maxBitrate;
bitrate = main_1.getSettings().settings.maxBitrate;
let obj;
try {
obj = yield main_1.addToQueue(dz, url, bitrate);

View file

@ -1,19 +1,10 @@
"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 });
const main_1 = require("../../../main");
const path = '/cancelAllDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const handler = (_, res) => {
main_1.cancelAllDownloads();
res.send({ result: true });
});
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -20,17 +20,15 @@ const LoginStatus = {
FORCED_SUCCESS: 3
};
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])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
const dz = main_1.sessionDZ[req.session.id];
if (!req.query) {
res.status(400).send();
return next();
return res.status(400).send();
}
if (!req.query.arl) {
res.status(400).send();
return next();
return res.status(400).send();
}
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
@ -52,11 +50,9 @@ const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
const testDz = new deezer_js_1.Deezer();
response = yield testDz.login_via_arl(...loginParams);
}
console.log(response);
const returnValue = { status: response, arl: req.query.arl, user: dz.current_user };
res.status(200).send(returnValue);
main_1.startQueue(dz);
next();
return res.status(200).send(returnValue);
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -1,21 +1,12 @@
"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 });
// @ts-expect-error
const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main");
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();
res.send({ logged_out: true });
});
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -1,19 +1,10 @@
"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 });
const main_1 = require("../../../main");
const path = '/removeFinishedDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const handler = (_, res) => {
main_1.clearCompletedDownloads();
res.send({ result: true });
});
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -1,17 +1,8 @@
"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 });
const main_1 = require("../../../main");
const path = '/removeFromQueue';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const handler = (req, res) => {
const { uuid } = req.query;
if (uuid) {
main_1.cancelDownload(uuid);
@ -20,6 +11,6 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
else {
res.send({ result: false });
}
});
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

@ -1,21 +1,12 @@
"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 });
const main_1 = require("../../../main");
const path = '/saveSettings';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const handler = (req, res) => {
const { settings, spotifySettings } = req.query;
main_1.saveSettings(settings, spotifySettings);
main_1.listener.send('updateSettings', { settings, spotifySettings });
res.send({ result: true });
});
};
const apiHandler = { path, handler };
exports.default = apiHandler;

View file

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

View file

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

View file

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

View file

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

View file

@ -19,7 +19,7 @@ const LoginStatus = {
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()
const dz = sessionDZ[req.session.id]

View file

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