diff --git a/server/dist/main.js b/server/dist/main.js
index 6325276..69837e7 100644
--- a/server/dist/main.js
+++ b/server/dist/main.js
@@ -12,13 +12,14 @@ 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.getQueue = exports.saveSettings = exports.getSettings = exports.listener = exports.plugins = exports.getArlFromAccessToken = exports.getAccessToken = exports.sessionDZ = 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.isDeezerAvailable = exports.deemixVersion = 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");
// @ts-expect-error
const deemix_1 = __importDefault(require("deemix"));
const ws_1 = __importDefault(require("ws"));
+const got_1 = __importDefault(require("got"));
const app_1 = require("./app");
const errors_1 = require("./helpers/errors");
const Downloader = deemix_1.default.downloader.Downloader;
@@ -29,6 +30,28 @@ 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.deemixVersion = require('../../node_modules/deemix/package.json').version;
+let deezerAvailable = null;
+function isDeezerAvailable() {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (deezerAvailable === null) {
+ let response;
+ try {
+ response = yield got_1.default.get('https://www.deezer.com/', {
+ headers: { Cookie: 'dz_lang=en; Domain=deezer.com; Path=/; Secure; hostOnly=false;' }
+ });
+ }
+ catch (_a) {
+ deezerAvailable = false;
+ return deezerAvailable;
+ }
+ const title = (response.body.match(/
]*>([^<]+)<\/title>/)[1] || '').trim();
+ deezerAvailable = title !== 'Deezer will soon be available in your country.';
+ }
+ return deezerAvailable;
+ });
+}
+exports.isDeezerAvailable = isDeezerAvailable;
exports.plugins = {
// eslint-disable-next-line new-cap
spotify: new deemix_1.default.plugins.spotify()
diff --git a/server/dist/routes/api/post/login-arl.js b/server/dist/routes/api/post/login-arl.js
index 9364469..3500f6c 100644
--- a/server/dist/routes/api/post/login-arl.js
+++ b/server/dist/routes/api/post/login-arl.js
@@ -50,6 +50,8 @@ const handler = (req, res, _) => __awaiter(void 0, void 0, void 0, function* ()
const testDz = new deezer_js_1.Deezer();
response = yield testDz.login_via_arl(...loginParams);
}
+ if (!(yield main_1.isDeezerAvailable()))
+ response = LoginStatus.NOT_AVAILABLE;
const returnValue = { status: response, arl: req.query.arl, user: dz.current_user };
main_1.startQueue(dz);
return res.status(200).send(returnValue);
diff --git a/server/dist/routes/index.js b/server/dist/routes/index.js
index fe8768d..25af03a 100644
--- a/server/dist/routes/index.js
+++ b/server/dist/routes/index.js
@@ -1,4 +1,13 @@
"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 };
};
@@ -8,6 +17,7 @@ const express_1 = __importDefault(require("express"));
const deezer_js_1 = require("deezer-js");
const main_1 = require("../main");
const router = express_1.default.Router();
+let update = null;
/**
* GET home page
*
@@ -16,25 +26,28 @@ const router = express_1.default.Router();
router.get('/', (_, res) => {
res.render('index', { title: 'deemix' });
});
-router.get('/connect', (req, res) => {
+router.get('/connect', (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];
- const result = {
- update: {
+ if (!update) {
+ update = {
currentCommit: 'testing',
latestCommit: 'testing',
updateAvailable: false,
- deemixVersion: '3.0_beta'
- },
+ deemixVersion: main_1.deemixVersion
+ };
+ }
+ const result = {
+ update,
autologin: !dz.logged_in,
currentUser: dz.current_user,
- deezerNotAvailable: false
+ deezerAvailable: yield main_1.isDeezerAvailable()
};
const queue = main_1.getQueue();
if (Object.keys(queue.queue).length > 0) {
result.queue = queue;
}
res.send(result);
-});
+}));
exports.default = router;
diff --git a/server/src/main.ts b/server/src/main.ts
index 3625fe1..d9750e2 100644
--- a/server/src/main.ts
+++ b/server/src/main.ts
@@ -20,18 +20,23 @@ export const getAccessToken = deemix.utils.deezer.getAccessToken
export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken
export const deemixVersion = require('../../node_modules/deemix/package.json').version
-export let deezerAvailable: boolean | null = null
+let deezerAvailable: boolean | null = null
-export async function isDeezerAvailable(): Promise{
- let response
- try {
- response = await got.get('https://www.deezer.com/', {headers: {'Cookie': 'dz_lang=en; Domain=deezer.com; Path=/; Secure; hostOnly=false;'}})
- } catch {
- deezerAvailable = false
- return
+export async function isDeezerAvailable(): Promise {
+ if (deezerAvailable === null) {
+ let response
+ try {
+ response = await got.get('https://www.deezer.com/', {
+ headers: { Cookie: 'dz_lang=en; Domain=deezer.com; Path=/; Secure; hostOnly=false;' }
+ })
+ } catch {
+ deezerAvailable = false
+ return deezerAvailable
+ }
+ const title = (response.body.match(/]*>([^<]+)<\/title>/)![1] || '').trim()
+ deezerAvailable = title !== 'Deezer will soon be available in your country.'
}
- const title = (response.body.match(/]*>([^<]+)<\/title>/)![1] || "").trim()
- deezerAvailable = title !== "Deezer will soon be available in your country."
+ return deezerAvailable
}
export const plugins: any = {
diff --git a/server/src/routes/api/post/login-arl.ts b/server/src/routes/api/post/login-arl.ts
index be4e926..311f697 100644
--- a/server/src/routes/api/post/login-arl.ts
+++ b/server/src/routes/api/post/login-arl.ts
@@ -1,7 +1,7 @@
import { RequestHandler } from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
-import { sessionDZ, startQueue, deezerAvailable, isDeezerAvailable } from '../../../main'
+import { sessionDZ, startQueue, isDeezerAvailable } from '../../../main'
import { ApiHandler } from '../../../types'
export interface RawLoginArlQuery {
@@ -22,7 +22,6 @@ const path: ApiHandler['path'] = '/login-arl'
const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id]
- if (deezerAvailable === null) await isDeezerAvailable()
if (!req.query) {
return res.status(400).send()
@@ -53,7 +52,7 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _
const testDz = new Deezer()
response = await testDz.login_via_arl(...loginParams)
}
- if (!deezerAvailable) response = LoginStatus.NOT_AVAILABLE
+ if (!(await isDeezerAvailable())) response = LoginStatus.NOT_AVAILABLE
const returnValue = { status: response, arl: req.query.arl, user: dz.current_user }
startQueue(dz)
diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts
index 85dc3bd..30b08e2 100644
--- a/server/src/routes/index.ts
+++ b/server/src/routes/index.ts
@@ -1,7 +1,7 @@
import express from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
-import { sessionDZ, getQueue, deemixVersion, isDeezerAvailable, deezerAvailable } from '../main'
+import { sessionDZ, getQueue, deemixVersion, isDeezerAvailable } from '../main'
const router = express.Router()
let update: any = null
@@ -27,13 +27,12 @@ router.get('/connect', async (req, res) => {
deemixVersion
}
}
- if (deezerAvailable === null) await isDeezerAvailable()
const result: any = {
update,
autologin: !dz.logged_in,
currentUser: dz.current_user,
- deezerAvailable
+ deezerAvailable: await isDeezerAvailable()
}
const queue = getQueue()