From 6183f9b7a668086dffb3cfaf501793b1f8580cb1 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 29 Jun 2021 00:06:11 +0200 Subject: [PATCH] Added correct deemix lib version + check deezer availability --- package.json | 2 +- server/src/main.ts | 16 ++++++++++++++++ server/src/routes/api/post/login-arl.ts | 4 +++- server/src/routes/index.ts | 20 +++++++++++++------- webui | 2 +- yarn.lock | 8 ++++---- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 8815fde..aabd191 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "electron-window-state-manager": "^0.3.2", "cookie-parser": "1.4.5", "debug": "2.6.9", - "deemix": "0.2.5", + "deemix": "3.0.0", "deezer-js": "1.0.0", "dotenv": "8.2.0", "express": "4.17.1", diff --git a/server/src/main.ts b/server/src/main.ts index 0eba816..3625fe1 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid' // @ts-expect-error import deemix from 'deemix' import WebSocket from 'ws' +import got from 'got' import { wss } from './app' import { Settings } from './types' import { NotLoggedIn } from './helpers/errors' @@ -18,6 +19,21 @@ let settings: any = deemix.settings.load(configFolder) 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 + +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 + } + const title = (response.body.match(/]*>([^<]+)<\/title>/)![1] || "").trim() + deezerAvailable = title !== "Deezer will soon be available in your country." +} + export const plugins: any = { // eslint-disable-next-line new-cap spotify: new deemix.plugins.spotify() diff --git a/server/src/routes/api/post/login-arl.ts b/server/src/routes/api/post/login-arl.ts index adc799e..be4e926 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 } from '../../../main' +import { sessionDZ, startQueue, deezerAvailable, isDeezerAvailable } from '../../../main' import { ApiHandler } from '../../../types' export interface RawLoginArlQuery { @@ -22,6 +22,7 @@ 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() @@ -52,6 +53,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 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 9b23636..85dc3bd 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -1,9 +1,10 @@ import express from 'express' // @ts-expect-error import { Deezer } from 'deezer-js' -import { sessionDZ, getQueue } from '../main' +import { sessionDZ, getQueue, deemixVersion, isDeezerAvailable, deezerAvailable } from '../main' const router = express.Router() +let update: any = null /** * GET home page @@ -14,20 +15,25 @@ router.get('/', (_, res) => { res.render('index', { title: 'deemix' }) }) -router.get('/connect', (req, res) => { +router.get('/connect', async (req, res) => { if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() const dz = sessionDZ[req.session.id] - const result: any = { - update: { + if (!update) { + update = { currentCommit: 'testing', latestCommit: 'testing', updateAvailable: false, - deemixVersion: '3.0_beta' - }, + deemixVersion + } + } + if (deezerAvailable === null) await isDeezerAvailable() + + const result: any = { + update, autologin: !dz.logged_in, currentUser: dz.current_user, - deezerNotAvailable: false + deezerAvailable } const queue = getQueue() diff --git a/webui b/webui index 03da7e2..b677f42 160000 --- a/webui +++ b/webui @@ -1 +1 @@ -Subproject commit 03da7e24df57fa2d508ad4bb87a5bda1a0bbd130 +Subproject commit b677f422a2faafc83b9c5142b63a17803a9f7d8a diff --git a/yarn.lock b/yarn.lock index 1e187cd..58156a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2269,10 +2269,10 @@ decompress-response@^6.0.0: dependencies: mimic-response "^3.1.0" -deemix@0.2.5: - version "0.2.5" - resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.2.5.tgz#d7e8c97de087d32b0030f3c0062a7e8ea6268ca6" - integrity sha512-BsxtCoXJ2wCxqiWEZYC6n+4wqr0Z6cpqqY6DgE4DGQGG6u+5shwew9/IGGtq47jAx1ysrJwz03FhdSnQTAXUTQ== +deemix@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/deemix/-/deemix-3.0.0.tgz#4a0ae0d5ebb75331b8909f60bbe444a0557ae201" + integrity sha512-tRtx6brWVm2ZMh79E61gXQGs2tD7h12TL9jmrRtucK9fZxZl59mH4S0QIZeLLovjF4/13MCWwtx/QvFLauM96g== dependencies: async "^3.2.0" crypto "^1.0.1"